spring boot gradle plugin change project dependencies version - spring-boot

I ran into a problem that puzzled me.
I use gradle build spring-boot project and i want package a runtime jar.
this is my dependencies :
buildscript {
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.5.RELEASE")
}
}
plugins {
id 'org.springframework.boot' version '1.5.5.RELEASE'
}
dependencies {
....
compile 'org.elasticsearch:elasticsearch:5.0.0'
compile 'org.elasticsearch.client:transport:5.0.0'
....
}
i run the cmd gradle dependencies :
+--- org.elasticsearch:elasticsearch:5.0.0 -> 2.4.5
| | +--- org.apache.lucene:lucene-core:5.5.4
| | +--- org.apache.lucene:lucene-backward-codecs:5.5.4
| | | \--- org.apache.lucene:lucene-core:5.5.4
| | +--- org.apache.lucene:lucene-analyzers-common:5.5.4
when i remove spring-boot plugin, Everything is normal.
i change spring-boot plugin version. some time There are some dependencies Will change the version.
please help me check it question, thx !

Related

Enforce the highest version from among several conflicting transitive dependencies in gradle

I work on a large project with multiple services and libraries, mostly in grails, with gradle builder. I'm trying to update a library (say logback) for security reasons.
I already updated it in one of our libraries (say our-logger), like so:
#our-logger/build.gradle
...
dependencies {
...
compile 'ch.qos.logback:logback-classic:1.2.3'
...
}
when I update a service (say our-service) to use the new version of our-logger i get logback included from other libraries, and gradle chooses the lower version coming through cobertura and some other dependencies, instead of the higher version coming through our-logger.
#our-service/build.gradle
...
apply plugin: 'cobertura'
...
dependencies {
...
compile 'our-logger:9.99' # safe now with logback-1.2.3
...
}
~/our-service $ ./gradlew dependencies
...
cobertura
\--- net.sourceforge.cobertura:cobertura:2.1.1
+--- ch.qos.logback:logback-classic:1.0.13 -> 1.1.11
| \--- ch.qos.logback:logback-core:1.1.11
...
compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
+--- org.grails:grails-dependencies:3.3.8
| +--- org.springframework.boot:spring-boot-starter-logging:1.4.2.RELEASE -> 1.5.15.RELEASE
| | +--- ch.qos.logback:logback-classic:1.1.11
| | | +--- ch.qos.logback:logback-core:1.1.11
...
+--- our-logger:9.99
| +--- ch.qos.logback:logback-classic:1.2.3 -> 1.1.11 (*)
How do I enforce logback-1.2.3 without explicitly declaring it in all services?
The gradle docs file this under Advanced Dependency Management. You should be able to satisfy your goal using excludes. There are other ways too Gradle Docs
compile(“some:other:dependency”) {
exclude group: 'ch.qos.logback', module: 'logback-classic'
}

Gradle dependency conflict when using `implementation`

I have a project with two gradle modules: lib and app. I just changed lib's build.gradle to stop exposing a dependency (i.e. I moved from api -> implementation). The app module doesn't directly depend on OkHttp logging interceptor so I figure it's better to not expose it.
lib module's build.gradle:
dependencies {
// api 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
...
}
app module's build.gradle:
dependencies {
implementation project(':lib')
implementation group: 'com.zendesk', name: 'support-providers', version: '2.0.0'
...
}
However I'm now seeing a compile problem:
Conflict with dependency 'com.squareup.okhttp3:logging-interceptor' in
project ':app'. Resolved versions for runtime classpath (3.10.0) and
compile classpath (3.8.1) differ
If I look at project structure I see this:
+--- project :lib
...
+--- com.zendesk:support-providers:2.0.0
| +--- com.zendesk:core:1.0.0
| | +--- com.zendesk:java-common:1.13
| | +--- com.google.dagger:dagger:2.12 -> 2.15 (*)
| | +--- com.squareup.retrofit2:retrofit:2.3.0
| | | \--- com.squareup.okhttp3:okhttp:3.8.0 -> 3.8.1
| | | \--- com.squareup.okio:okio:1.13.0
| | +--- com.squareup.retrofit2:converter-gson:2.3.0
| | | +--- com.squareup.retrofit2:retrofit:2.3.0 (*)
| | | \--- com.google.code.gson:gson:2.7
| | +--- com.squareup.okhttp3:logging-interceptor:3.8.1 // <----- SEE HERE
| | | \--- com.squareup.okhttp3:okhttp:3.8.1 (*)
| | +--- com.squareup.okhttp3:okhttp:3.8.1 (*)
| | +--- com.android.support:support-annotations:27.0.2 -
lib isn't revealing any of it's dependencies (obviously) and app depends on Zendesk sdk which depends on different version of OkHttp logging interceptor.
I only see two ways to fix this:
revert api -> implementation in lib module, thus exposing logging interceptor to app module
declare a top level dependency on logging interceptor and set to 3.10 to force Zendesk to use latest:
app build.gradle:
dependencies {
implementation project(':lib')
implementation group: 'com.zendesk', name: 'support-providers', version: '2.0.0'
// used just to force zendesk to use 3.10
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
...
}
Neither of these seem very clean. IMO the app module shouldn't know anything about OkHttp logging interceptor. Is there another option?
If Zendesk updated their library to use implementation for their OkHttp dependency would this solve the problem? Will Gradle let two dependencies use different versions of the same transitive dependency as long as they don't expose to the project as a whole?
with Gradle this works a little different ...
one can either enforce the version 3.10.0:
dependencies {
implementation group: 'com.zendesk', name: 'support-providers', version: '2.0.0'
}
configurations.all() {
resolutionStrategy.force "com.squareup.okhttp3:logging-interceptor:3.10.0"
}
or just exclude version 3.8.1 (which is leaving nothing but the desired version 3.10.0):
dependencies {
implementation ('com.zendesk:support-providers:2.0.0") {
exclude "com.squareup.okhttp3:logging-interceptor:3.8.1"
}
}

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.
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.
There is some conflict with another dependency that is pulling the older 1.1.0 in the compile classpath.
This means that some other library which has higher priority in gradle build order is dependent the older 1.1.0 version.
You can see here more info on how to specify the gradle build order.
I met similar problems, then I found it caused by using the Dependency management in gradle:
plugins {
...
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Hoxton.SR8"
}
}
this dependency management impact the transitive dependency version solution. after comment it out. all the version is correct.

Determine source of dependency version override in Gradle

I have declared a dependency for org.spockframework:spock-spring:1.1.d91bf785-groovy-2.4, but in runtime scope it is overridden to 1.0-groovy-2.4. Is there a way to figure out which dependency is overriding it?
1.0-groovy-2.4 is not present in any gradle file locally, and it is not visible when I run gradle dependencies in the shared-config project.
Here's gradle dependencies from the main-web project:
testCompile
[...]
+--- project :shared-config
| [...]
| +--- org.spockframework:spock-spring:1.1.d91bf785-groovy-2.4
[...]
runtime
[...]
+--- project :shared-config
| [...]
| +--- org.spockframework:spock-spring:1.1.d91bf785-groovy-2.4 -> 1.0-groovy-2.4
| | +--- org.spockframework:spock-core:1.0-groovy-2.4 -> 1.1.d91bf785-groovy-2.4
| | \--- org.codehaus.groovy:groovy-all:2.4.1 -> 2.4.12
dependencyInsight gives some insight:
$ gradle dependencyInsight --dependency org.spockframework:spock-spring:1.0-groovy-2.4 --configuration runtime
> Task :main-web:dependencyInsight
org.spockframework:spock-spring:1.0-groovy-2.4 (selected by rule)
org.spockframework:spock-spring:1.1.d91bf785-groovy-2.4 -> 1.0-groovy-2.4
\--- project :shared-config
\--- runtime
But the same command in the shared-config project doesn't yield any results:
No dependencies matching given input were found in configuration ':shared-config:runtime'
I have tried overriding the version without success:
configurations.all {
resolutionStrategy {
force "org.spockframework:spock-spring:1.1.d91bf785-groovy-2.4"
}
}
Seems like you are using spring boot as a parent or spring boot dependencies as a bom (dependency manager)
by default in latest spring boot versions 1.5 + spock.version is set to 1.0-groovy-2.4 that's why spock-core still have old version.
In order to fix this in gradle you need to override property spock.version in your gradle app. By adding spock.version = 1.1-groovy-2.4 to gradle.properties file.
Visit Spring doc for overriding dep properties to find more.

Finding unwanted code dependencies on transitive dependencies

I want to find all my Java code dependencies on libraries that I have not included as top level dependencies in Gradle.
My first though as to how to accomplish this is to turn off all transitive dependencies in Gradle and see what compilation errors I get.
From my research the way to do this seems to be:
configurations.all { transitive = false }
Is there a better way, or does this do it?
I'm not sure I understand the question, but the command line "gradle dependencies" might help.
For example, consider this (from this modest project):
dependencies {
groovy 'org.codehaus.groovy:groovy-all:1.6.4'
groovy 'com.google.guava:guava-collections:r03'
releaseJars 'org.codehaus.groovy:groovy-all:1.6.4'
releaseJars 'com.google.guava:guava-collections:r03'
}
Using gradle dependencies gives output such as:
compile - Classpath for compiling the main sources.
+--- org.codehaus.groovy:groovy-all:1.6.4
| +--- junit:junit:3.8.2
| +--- org.apache.ant:ant:1.7.1
| | \--- org.apache.ant:ant-launcher:1.7.1
| +--- org.apache.ant:ant-launcher:1.7.1
| \--- jline:jline:0.9.94
| \--- junit:junit:3.8.1 -> 3.8.2
\--- com.google.guava:guava-collections:r03
+--- com.google.guava:guava-annotations:r03
\--- com.google.guava:guava-primitives:r03
....

Resources