Java Gradle自动升级依赖项的版本

Java Gradle自动升级依赖项的版本,java,gradle,Java,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-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. */
    }
}
注意:我使用了
gradleinit
将maven转换为gradle项目。

更新-1 我注意到这个
ref-arch-restapi-base
依赖项有spring的5.1.2.0版本


还没有运气,有人能帮上忙吗?

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

./gradlew dependencyInsight --configuration compileClasspath --dependency spring-core
这将为您提供一个与问题顶部相反的视图,您将能够了解导致版本升级的依赖路径

然而,鉴于您对
ref arch restapi base
的依赖关系的评论,这很可能是升级的原因

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


如果您严格要求使用Spring 5.0版本,您可能需要将
ref-arch rest api base
降级为该版本。

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

./gradlew dependencyInsight --configuration compileClasspath --dependency spring-core
这将为您提供一个与问题顶部相反的视图,您将能够了解导致版本升级的依赖路径

然而,鉴于您对
ref arch restapi base
的依赖关系的评论,这很可能是升级的原因

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


如果您严格要求使用Spring 5.0版本,您可能需要将
ref-arch rest api base
降级到该版本。

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

  • 导入的BOM如下所示
  • 依赖管理{
    进口{
    mavenBom“org.springframework.boot:spring引导依赖项:$springBootVersion”
    }
    }
    
    2.然后包括依赖项,当需要时,这些依赖项在依赖项块中定义。通过这样做,Gradle不会自动升级版本


    只是将此作为参考发布给其他人。

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

  • 导入的BOM如下所示
  • 依赖管理{
    进口{
    mavenBom“org.springframework.boot:spring引导依赖项:$springBootVersion”
    }
    }
    
    2.然后包括依赖项,当需要时,这些依赖项在依赖项块中定义。通过这样做,Gradle不会自动升级版本


    只是将此作为参考发布给其他人。

    可能与否重复,我尝试过此操作,但仍然面临相同的问题。您可以发布您的gradle dependencies代码吗here@vikaskumar更新了我的问题。可能是重复的否,我尝试过这个,仍然面临同样的问题。你能发布你的gradle依赖代码吗here@vikaskumar更新了我的问题。