Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle is selecting wrong dependency version

I am seeing some weirdness in my Gradle build. I have a Spring Boot app (which uses Gradle for its build) and am trying to pull in both the Hibernate Validator as well as Hibernate Core. Here's the dependencies declaration in my build.gradle file:

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web') {
        exclude module: 'spring-boot-starter-tomcat'
    }

    compile(
        'org.codehaus.groovy:groovy-all:2.4.12'
        ,'com.google.inject:guice:4.1.0'
        ,'ch.qos.logback:logback-classic:1.2.3'
        ,'org.slf4j:jul-to-slf4j:1.7.25'
        ,'org.apache.logging.log4j:log4j-to-slf4j:2.9.1'
        ,'commons-cli:commons-cli:1.4'
        ,'org.apache.commons:commons-lang3:3.7'
        ,'io.dropwizard.metrics:metrics-core:3.2.5'
        ,'io.dropwizard.metrics:metrics-json:3.2.5'
        ,'org.springframework.security:spring-security-jwt:1.0.9.RELEASE'
        ,'org.springframework.security.oauth:spring-security-oauth2:2.2.1.RELEASE'
        ,'io.jsonwebtoken:jjwt:0.9.0'
        ,'org.hibernate:hibernate-validator:6.0.7.Final'
        ,'mysql:mysql-connector-java:6.0.6'
        ,'org.hibernate:hibernate-core:5.2.12.Final'

        ,'com.h2database:h2:1.4.196'

        ,'org.springframework.boot:spring-boot-starter-jetty'
        ,'org.springframework.boot:spring-boot-starter-actuator'
        ,'org.springframework.boot:spring-boot-starter-security'
        ,'org.springframework.boot:spring-boot-starter-data-rest'
        ,'org.springframework.boot:spring-boot-starter-data-jpa'
    )

    dev('org.springframework.boot:spring-boot-devtools')

    testCompile(
        'org.spockframework:spock-core:1.0-groovy-2.4'
        ,'junit:junit:4.12'
    )
}

When I run ./gradlew dependencies I get a huge output, but from the compile dependencies tree I see the following:

|    +--- org.springframework.boot:spring-boot-starter:1.5.8.RELEASE
|    +--- org.hibernate:hibernate-validator:5.3.5.Final -> 6.0.7.Final
|    |    \--- org.hibernate.validator:hibernate-validator:6.0.7.Final
|    |         +--- javax.validation:validation-api:2.0.1.Final -> 1.1.0.Final
|    |         +--- org.jboss.logging:jboss-logging:3.3.0.Final -> 3.3.1.Final
|    |         \--- com.fasterxml:classmate:1.3.1 -> 1.3.4

So to me it looks like spring-boot-starter:1.5.8.RELEASE is pulling in validation-api:2.0.1.Final but for some reason Gradle is selecting validation-api:1.1.0.Final for me...am I reading that correctly? In my IDE compile classpath I only see validation-api:1.1.0.Final, not 2.0.1.Final.

Why is Gradle selecting 1.1.0.Final instead of 2.0.1.Final? I ask because Hibernate Validator 5.x is not compatible with Validation API 1.x and when my app runs I get all sorts of Hibernate Validation-related errors.

Update

Some more output:

gradle -q dependencyInsight --configuration compile --dependency validation-api
javax.validation:validation-api:1.1.0.Final (selected by rule)

javax.validation:validation-api:2.0.1.Final -> 1.1.0.Final
\--- org.hibernate.validator:hibernate-validator:6.0.7.Final
     \--- org.hibernate:hibernate-validator:6.0.7.Final
          +--- compile
          \--- org.springframework.boot:spring-boot-starter-web:1.5.8.RELEASE
               +--- compile
               \--- org.springframework.boot:spring-boot-starter-data-rest:1.5.8.RELEASE
                    \--- compile

The full compile configuration output can be found here.

like image 390
smeeb Avatar asked Oct 16 '25 08:10

smeeb


1 Answers

The version is enforced by Spring Boot.

See the POM for the Spring Boot dependencies: http://search.maven.org/remotecontent?filepath=org/springframework/boot/spring-boot-dependencies/1.5.8.RELEASE/spring-boot-dependencies-1.5.8.RELEASE.pom and look for "javax-validation.version".

See https://docs.spring.io/platform/docs/Brussels-SR4/reference/html/getting-started-overriding-versions.html for more information on how to override Spring Boot versions.

I would recommend overriding directly "javax-validation.version" and "hibernate-validator.version" instead of redefining the dependencies.

like image 154
Guillaume Smet Avatar answered Oct 18 '25 12:10

Guillaume Smet



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!