Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle dependency management to force version

Tags:

gradle

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:

  • Spring gradle dependency management plugin https://docs.spring.io/dependency-management-plugin/docs/1.0.8.RELEASE/reference/html/
  • Gradle dependency constraints https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html#sec:dependency_constraints
  • 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'
        }
    }
    
like image 469
sendon1982 Avatar asked Dec 13 '25 13:12

sendon1982


1 Answers

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.

like image 136
Francisco Mateo Avatar answered Dec 16 '25 23:12

Francisco Mateo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!