I made a decision to migrate from Dependency Management Plugin to Gradle built-in BOM import support. Since Gradle built-in BOM import support has better performance But
I run into the issue:
I cannot find alternatives for dependency and dependencySet in native Gradle:
    dependencyManagement {
        dependencies {
            dependency("org.springframework:spring-core:4.0.3.RELEASE")
        }
    }
//or
    dependencyManagement {
         dependencies {
              dependencySet(group:'org.slf4j', version: '1.7.7') {
                   entry 'slf4j-api'
                   entry 'slf4j-simple'
              }
         }
    }
and then I could use dependency without version
dependencies {
    compile 'org.springframework:spring-core'
}
How can I get the same behavior in naive Gradle? I mean: I'd like to define a version once as I did it when using Dependency Management Plugin
Solution below helps to avoid versions copy-paste. However it isn't the same with Dependency Management plugin.
For Gradle Kotlin Dsl:
You can create buildSrc with you own code, when you can place any constants.
Algorithm:
buildSrc/src/main/kotlinbuildSrc/src/main/kotlin/Versions.kt with content:object Versions {
    const val junitVersion = "5.5.5" // just example
}
buildSrc/build.gradle.kts with content:plugins {
    `kotlin-dsl`
}
dependencies {
    testImplementation("org.junit.jupiter:junit-jupiter:${Versions.junitVersion}")
}
For Gradle Groovy:
gradle.propertiesokhttp_version=4.2.0dependencies {
    compile group: 'com.squareup.okhttp3', name: 'okhttp', version: okhttp_version
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With