nowinandroid icon indicating copy to clipboard operation
nowinandroid copied to clipboard

Hotfix broken build with a test

Open Jaehwa-Noh opened this issue 1 year ago • 5 comments

What I have done and why

Fix #1544

Jaehwa-Noh avatar Jul 12 '24 04:07 Jaehwa-Noh

@machado001 Thanks for your comment.

From this documentation. https://kotlinlang.org/docs/gradle-configure-project.html#set-dependencies-on-test-libraries

You can use shorthand for a dependency on a Kotlin module, for example, kotlin("test") for "org.jetbrains.kotlin:kotlin-test".

We use Kotlin DSL and it gives us kotlin shorthand kotlin("test")

kotlin("test") is more shorten and clear than version catalog, and it reduces that what we have to manage a dependency as we delegate it to kotlin.

I found same thing on Groovy also can use shorthand.

kotlin {
    sourceSets {
        commonTest {
            dependencies {
                implementation kotlin("test") // This brings all the platform dependencies automatically
            }
        }
    }
}

Jaehwa-Noh avatar Jul 14 '24 00:07 Jaehwa-Noh

Hi @Jaehwa-Noh, thank you for your reply.

I agree that using kotlin("test") is clean enough. Just to provide another perspective, I suggested adding the library to the version catalog to maintain project consistency and have a centralized place to manage and document dependencies.

New developers can start contributing to the project by looking at the version catalog file to get a general overview of the libraries and plugins used in the project.

I checked another build.gradle.kts file, particularly from the :lint module, and it looks like kotlin("test") is already used there. This could become a recurrent dependency that isn't declared in the version catalog, requiring developers to check each module individually to discover this.

Thus, another advantage is that, from the version catalog, developers can simply Ctrl + click (or Ctrl + B) to check which modules use the dependency.

machado001 avatar Jul 14 '24 01:07 machado001

@machado001 Yes, you have the reason. Simple way is you can found all usage in search all files Ctrl + Shift + F (Find all files). On this topic, I can't determine which way is better on my own. Let us hear the other developers' and maintainers' opinions.

Jaehwa-Noh avatar Jul 14 '24 01:07 Jaehwa-Noh

I would prefer the explicit declaration of kotlin-test dependency in libs.versionss.toml.

trietbui85 avatar Jul 14 '24 02:07 trietbui85

Following #1560, not only fixed #1544 but also replaced kotlin("test") to version catalog kotlin.test for consistent.

Jaehwa-Noh avatar Sep 14 '24 02:09 Jaehwa-Noh

Superseded #1667

Jaehwa-Noh avatar Nov 09 '24 12:11 Jaehwa-Noh