Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Move version number to a variable in Gradle Kotlin DSL

My build.gradle.kts contains my dependencies like this:

dependencies {
    implementation("io.insert-koin:koin-core:3.1.6")
    implementation("io.insert-koin:koin-test:3.1.6")
    testImplementation(kotlin("test"))
}

How can I move the 3.1.6 to a local variable (?) so I can avoid duplicating it in several places.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you just want it local, you can add a value to your dependencies block:
dependencies {
val koinVersion = "3.1.6"

implementation("io.insert-koin:koin-core:$koinVersion")
implementation("io.insert-koin:koin-test:$koinVersion")
testImplementation(kotlin("test"))

}

If you want to use it multiple spots, you can add an extra value in your project’s build.gradle.kts file:

val koinVersion by extra { "3.1.6" }

then in the app’s build.gradle.kts file, you import it before using it:

val koinVersion: String by rootProject.extra

dependencies {
    implementation("io.insert-koin:koin-core:$koinVersion")
    implementation("io.insert-koin:koin-test:$koinVersion")
    testImplementation(kotlin("test"))
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading