javaspringgradledependency-managementspring-hateoas

Gradle Not Honoring Forced Dependency Version


I am unable to force a version of a dependency using Gradle. My goal is to use version 0.20.0.RELEASE of the Spring HATEOAS library, but despite all my efforts it keeps resolving to 0.19.0.RELEASE.

I have attempted a number of strategies, both in isolation and in combination with one another. These strategies include, but are possibly not limited to, the following (note that in all cases $springHateoasVersionis defined in the gradle.properties file that resides in the directory that is the parent of the directory for the module declaring the Spring HATEOAS dependency):

#1 (in the build.gradle file for the module that declares the dependency)

apply plugin: 'io.spring.dependency-management'

dependencyManagement {
    dependencies {
        dependency group:'org.springframework.hateoas', name:'spring-hateoas', version:"$springHateoasVersion"
    }
}

#2 (in the build.gradle file for the module that declares the dependency)

compile ("org.springframework.hateoas:spring-hateoas:$springHateoasVersion") { force = true }

#3 (in the build.gradle file of the parent directory)

subprojects {
    configurations.all {
        resolutionStrategy {
            force "org.springframework.hateoas:spring-hateoas:$springHateoasVersion"
        }
    }
}

I have done my best to research this problem:

This question has an accepted answer, but doesn't seem like an exact match for the problem that I'm experiencing: How can I force Gradle to set the same version for two dependencies?

Neither of these questions seem to have accepted answers: 1) Gradle is not honoring resolutionStrategy.force, 2) Forcing a module version has no effect on generated org.eclipse.wst.common.component.

In addition to the fact that my project is broken (because I'm using the wrong version of Spring HATEOAS), I can explicitly see that Gradle is "consciously" selecting the incorrect dependency version despite all my protestations. When I run ./gradlew dependencyInsight --dependency spring-hateoas, I see the following output:

org.springframework.hateoas:spring-hateoas:0.19.0.RELEASE (selected by rule)

org.springframework.hateoas:spring-hateoas:0.20.0.RELEASE -> 0.19.0.RELEASE
\--- project :Commons
     \--- compile

Despite the name, the dependencyInsight task provides surprisingly little insight into which rule caused Gradle to select the inappropriate dependency version, let alone how I might go about circumventing said rule.


Solution

  • I found the solution to this problem here. Of course this was the one thing I didn't try because it "didn't seem material". :-/

    In order to get things working, I added the following to the build.gradle file of the parent directory (relative to the directory for the module that declared the dependency on Spring HATEOAS).

    subprojects {
        apply plugin: 'io.spring.dependency-management'
    
        dependencyManagement {
            applyMavenExclusions false
        }
    
        ext['spring-hateoas.version'] = "$springHateoasVersion"
    }