[英]Gradle upgrades versions of dependency automatically
I am new to Gradle.我是 Gradle 的新手。 I am facing the following problem.
我面临以下问题。
+--- org.springframework:spring-tx:5.0.5.RELEASE
| | +--- org.springframework:spring-beans:5.0.5.RELEASE -> 5.1.2.RELEASE (*)
| | \--- org.springframework:spring-core:5.0.5.RELEASE -> 5.1.2.RELEASE (*)
| +--- org.springframework:spring-context:5.0.5.RELEASE -> 5.1.2.RELEASE (*)
| +--- org.springframework:spring-beans:5.0.5.RELEASE -> 5.1.2.RELEASE (*)
| +--- org.springframework:spring-core:5.0.5.RELEASE -> 5.1.2.RELEASE (*)
| +--- org.springframework:spring-expression:5.0.5.RELEASE -> 5.1.2.RELEASE (*)
| +--- org.springframework.data:spring-data-commons:2.0.6.RELEASE -> 2.0.11.RELEASE
| | +--- org.springframework:spring-core:5.0.10.RELEASE -> 5.1.2.RELEASE (*)
| | +--- org.springframework:spring-beans:5.0.10.RELEASE -> 5.1.2.RELEASE (*)
As shown above, all of my dependencies are upgraded to the latest compatible versions.如上所示,我的所有依赖项都升级到最新的兼容版本。 This is causing a compilation error in one of my test cases.
这在我的一个测试用例中导致编译错误。
How can I ask Gradle to not to do this?我怎样才能让 Gradle 不这样做?
Using gradle version 3.0, if more details required I can post.使用 gradle 3.0 版,如果需要更多详细信息,我可以发布。
Please find the build.gradle
file below:请在下面找到
build.gradle
文件:
apply plugin: 'java'
apply plugin: 'maven'
group = 'com.abc.studentmanagement'
version = '1.0.0-SNAPSHOT'
description = """"""
project.sourceCompatibility = 1.8
project.targetCompatibility = 1.8
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
springRetryVersion = '1.2.2.RELEASE'
springCloudStarterVersion = '2.0.0.RC1'
springfoxSwaggerVersion = '2.9.2'
guavaVersion = '20.0'
mongoDBVersion = '3.10.1'
lombokVersion = '1.16.20'
swaggerRequestValidatorVersion = '1.3.9'
referenceArchVersion = '5.3.2'
junitVersion = '4.12'
karateJUnitVersion = '0.9.4'
refarchGradleCodegenPluginVersion = '1.0.2'
springVersion = "5.0.6.RELEASE"
}
repositories {
mavenLocal()
}
}
repositories {
mavenLocal()
}
dependencies {
compile (group: 'com.abc.refarch', name: 'ref-arch-rest-api-base', version: referenceArchVersion){
exclude(group: 'org.springframework')
}
compile (group: 'com.abc.refarch', name: 'ref-arch-rest-api-security', version: referenceArchVersion) {
exclude(group: 'org.springframework')
}
compile (roup: 'com.abc.refarch', name: 'ref-arch-logging-web', version: referenceArchVersion) {
exclude(group: 'org.springframework')
}
compile(group: 'com.abc.apie.restclient', name: 'restclient-sdk', version: '3.2.8') {
exclude(module: 'json-smart')
}
compile group: 'com.abc.apie.restclient', name: 'restclient-sdk', version: '1.10.3'
compile group: 'com.abc.apie.restclient', name: 'int-sdk', version: '1.4.3'
compile group: 'io.swagger', name: 'swagger-parser', version: '1.0.23'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compile group: 'org.apache.camel', name: 'camel-jsonpath', version: '2.22.0'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb', version: springBootVersion
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-vault-config', version: springCloudStarterVersion
compile group: 'com.google.gdata', name: 'core', version: '1.47.1'
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.8.10'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
compile group: 'io.pivotal.spring.cloud', name: 'spring-cloud-services-starter-config-client', version: springBootVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-bus-amqp', version: '2.0.0.RC1'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-aop', version: springBootVersion
compile group: 'org.springframework.retry', name: 'spring-retry', version: springRetryVersion
compile group: 'io.springfox', name: 'springfox-swagger2', version: springfoxSwaggerVersion
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: springfoxSwaggerVersion
compile group: 'com.google.guava', name: 'guava', version: guavaVersion
compile group: 'com.atlassian.oai', name: 'swagger-request-validator-core', version: swaggerRequestValidatorVersion
compile group: 'org.mongodb', name: 'mongodb-driver', version: mongoDBVersion
compile group: 'org.mongodb', name: 'mongodb-driver-core', version: mongoDBVersion
compile group: 'org.mongodb', name: 'bson', version: mongoDBVersion
compile group: 'com.abc.consumer.exception', name: 'exception-handler', version: '1.3.3-SNAPSHOT'
compile(group: 'com.abc.apie.alter', name: 'alter-sdk', version: '2.0.5') {
exclude(module: 'hibernate-validator')
}
compile(group: 'com.abc.refarch', name: 'ref-arch-messaging-base', version: '5.3.2') {
exclude(module: 'alter-sdk')
exclude(module: 'hibernate-validator')
}
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
testCompile group: 'com.abc.refarch', name: 'ref-arch-unit-test-jar', version: '5.3.2'
testCompile(group: 'com.intuit.karate', name: 'karate-apache', version: karateJUnitVersion) {
exclude(module: 'logback-classic')
}
testCompile group: 'com.intuit.karate', name: 'karate-junit4', version: karateJUnitVersion
testCompile group: 'net.masterthought', name: 'cucumber-reporting', version: '3.20.0'
compile(group: 'org.projectlombok', name: 'lombok', version: lombokVersion) {
/* This dependency was originally in the Maven provided scope, but the project was not of type war.
This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
Please review and delete this closure when resolved. */
}
}
NOTE: I Have used gradle init
to convert from maven to gradle project.注意:我已经使用
gradle init
从 maven 转换为 gradle 项目。
UPDATE-1 I noticed that this ref-arch-rest-api-base
dependency has this version 5.1.2.RELEASE of spring. UPDATE-1我注意到这个
ref-arch-rest-api-base
依赖有这个 spring 版本 5.1.2.RELEASE 。
No luck yet, can anyone help on this?还没有运气,有人可以帮忙吗?
In order to understand why a specific version of a dependency is used, run the dependencyInsight
task, so something like:为了了解为什么使用特定版本的依赖项,请运行
dependencyInsight
任务,例如:
./gradlew dependencyInsight --configuration compileClasspath --dependency spring-core
This will give you a reversed view compared to the one at the top of your question and you will be able to understand which dependency path causes the version upgrade.与问题顶部的视图相比,这将为您提供相反的视图,您将能够了解哪个依赖路径导致版本升级。
However given your comment on the dependencies of ref-arch-rest-api-base
, that's most likely the reason of the upgrade.但是,鉴于您对
ref-arch-rest-api-base
的依赖项的评论,这很可能是升级的原因。
By default, Gradle will use all the versions it sees in the dependency graph and resolve conflicts on version by upgrading to the highest, which is usually safe.默认情况下,Gradle 将使用它在依赖图中看到的所有版本,并通过升级到最高版本来解决版本冲突,这通常是安全的。
You might need to downgrade ref-arch-rest-api-base
to a version that works with Spring 5.0 if you strictly require that version.如果您严格要求该版本,您可能需要将
ref-arch-rest-api-base
降级到适用于 Spring 5.0 的版本。
Okay, I finally found a work around, I still don't know why gradle was upgrading the version automatically.好的,我终于找到了解决方法,我仍然不知道为什么gradle会自动升级版本。 My work around goes as mentioned below.
我的工作如下所述。
dependencyManagement { imports { mavenBom "org.springframework.boot:spring-boot-dependencies:$springBootVersion" } }
2. And then include the dependencies, as and when required, these dependencies are defined in the dependency block. dependencyManagement { imports { mavenBom "org.springframework.boot:spring-boot-dependencies:$springBootVersion" } }
2. 然后包含依赖,当需要时,这些依赖被定义在依赖块中。 By doing this the version is not upgraded by Gradle automatically.通过这样做,Gradle 不会自动升级版本。
Just posting this as a reference to others.只是将其发布为其他人的参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.