Reputation: 11304
What is the best way to do dependency management like in Maven <dependencyManagement>
tag ?
I did some research online and found out there are a few options:
Gradle configuration resolutionStrategy to force a version
configurations.all {
resolutionStrategy {
force 'com.google.guava:guava:14.0.1'
force 'com.google.guava:guava-gwt:14.0.1'
}
}
Upvotes: 3
Views: 2328
Reputation: 39095
I am using this way to force the version:
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'redis.clients') {
details.useVersion "3.0.1"
}
if (details.requested.group == 'com.github.jsqlparser') {
details.useVersion "2.1"
}
if (details.requested.group == 'com.squareup.okhttp3') {
details.useVersion "4.0.0"
}
if (details.requested.group == 'com.github.pagehelper' && !details.requested.name.contains('spring-boot')) {
details.useVersion("5.1.11")
}
}
}
}
hope this help for you.
Upvotes: 1
Reputation: 23060
Use Gradle's native support for importing BOMs:
From the docs here
dependencies {
// import a BOM
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.1.7.RELEASE"))
// define dependencies without versions
implementation("com.google.code.gson:gson")
implementation("dom4j:dom4j")
// import a BOM for test dependencies
testImplementation(platform("org.junit:junit-bom:5.5.1"))
// define dependency without versions
testImplementation("org.junit.jupiter:junit-jupiter")
}
I recommend watching Managing Dependencies for Spring Projects with Gradle by Jenn Strater and Andy Wilkinson to get some background as to why Spring's dependency management plugin exist and where the plugin itself and Gradle is going.
Upvotes: 2