sendon1982
sendon1982

Reputation: 11304

Gradle dependency management to force version

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:

Upvotes: 3

Views: 2328

Answers (2)

Dolphin
Dolphin

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

Cisco
Cisco

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

Related Questions