Gradle自动升级依赖版本

时间:2019-11-28 12:25:03

标签: java gradle

我是Gradle的新手。我面临以下问题。

  +--- 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 (*)

如上所述,我所有的依赖项都升级到了最新的兼容版本。这在我的一个测试用例中导致了编译错误。

我如何要求Gradle不这样做?

使用gradle 3.0版,如果需要更多详细信息,我可以发布。

请在下面找到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. */
    }
}

注意:我已经使用gradle init从maven转换为gradle项目。

UPDATE-1 我注意到,此ref-arch-rest-api-base依赖项的版本为5.1.2.RELEASE。

还没有运气,有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

为了了解为什么要使用特定版本的依赖项,请运行dependencyInsight任务,如下所示:

./gradlew dependencyInsight --configuration compileClasspath --dependency spring-core

与问题顶部的视图相比,这将为您提供相反的视图,并且您将能够了解导致版本升级的依赖路径。

但是,鉴于您对ref-arch-rest-api-base的依赖性的评论,这很可能是升级的原因。

默认情况下,Gradle将使用在依赖关系图中看到的 all 版本,并通过升级到最高版本来解决版本冲突,这通常是安全的。

如果严格要求该版本,则可能需要将ref-arch-rest-api-base降级到与Spring 5.0兼容的版本。

答案 1 :(得分:0)

好吧,我终于找到了解决方法,我仍然不知道为什么gradle自动升级了版本。我的解决方法如下所述。

  1. 改进的BOM,如下所示。

dependencyManagement { imports { mavenBom "org.springframework.boot:spring-boot-dependencies:$springBootVersion" } } 2.然后包括相关性,并在需要时在相关性块中定义这些相关性。这样,Gradle不会自动升级该版本。

仅发布此内容以供他人参考。