【问题标题】:Gradle resolutionStrategy does not override version as expectedGradle resolutionStrategy 没有按预期覆盖版本
【发布时间】:2017-04-21 10:12:20
【问题描述】:

我在子项目中定义了一个依赖,例如:

testCompile(
  "org.springframework:spring-test:4.3.7-RELEASE",
)

我的主要 build.gradle 覆盖了 resolutionStrategy:

subprojects {

  configurations {
    compileClasspath.transitive = false
    testCompileClasspath.transitive = false

    all*.resolutionStrategy {
      eachDependency { details ->
        def requested = details.requested

        switch (requested.group) {
           case 'org.springframework':
             details.useVersion '4.3.7-RELEASE'
             break
        }
      }
    }
  }
}

但是依赖被解析为(sn-p):

+--- org.springframework:spring-test:4.3.7.RELEASE (*)
|    +--- org.springframework:spring-core:4.3.7.RELEASE
|    \--- org.springframework:spring-aop:4.3.7.RELEASE
|         +--- org.springframework:spring-beans:4.3.7.RELEASE
|         |    \--- org.springframework:spring-core:4.3.7.RELEASE
|         \--- org.springframework:spring-core:4.3.7.RELEASE
|    |    \--- org.springframework:spring-context:4.3.7.RELEASE
|    |         +--- org.springframework:spring-aop:4.3.7.RELEASE (*)
|    |         +--- org.springframework:spring-beans:4.3.7.RELEASE (*)
|    |         +--- org.springframework:spring-core:4.3.7.RELEASE
|    |         \--- org.springframework:spring-expression:4.3.7.RELEASE -> 4.3.0.RC2
|    |              \--- org.springframework:spring-core:4.3.0.RC2 -> 4.3.7.RELEASE

注意org.springframework:spring-expression:4.3.7.RELEASE -> 4.3.0.RC2

为什么会这样?

我正在使用 Gradle 3.5

【问题讨论】:

    标签: gradle dependencies


    【解决方案1】:

    试试这个:

    all.resolutionStrategy {
      eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'org.springframework') {
          details.useVersion '4.3.7-RELEASE'
        }
      }
    }
    

    取自https://docs.gradle.org/3.5/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

    【讨论】:

      猜你喜欢
      • 2018-07-17
      • 1970-01-01
      • 1970-01-01
      • 2021-10-04
      • 2015-10-07
      • 1970-01-01
      • 2021-03-29
      • 2021-01-13
      • 1970-01-01
      相关资源
      最近更新 更多