渐变中的库版本已降级



执行时(在6.5级中(

./gradlew dependencyInsight --dependency groovy-testng --configuration testRuntimeClasspath

我可以发现groovy-testng来自添加到我们的build.gradle中的groovy-all库。我想更新groovy-testng的版本,所以我决定更新groovy-all,根据mvnrepository,它在3.0.4版本中包含groovy-testng,但groovy-testng的版本仍然是旧版本,gradle没有将其解析为最新版本:

org.codehaus.groovy:groovy-testng:2.5.12 (selected by rule)
variant "runtime" [
org.gradle.status              = release (not requested)
org.gradle.usage               = java-runtime
org.gradle.libraryelements     = jar
org.gradle.category            = library
Requested attributes not found in the selected variant:
org.gradle.dependency.bundling = external
org.gradle.jvm.version         = 11
]
org.codehaus.groovy:groovy-testng:3.0.4 -> 2.5.12
--- org.codehaus.groovy:groovy-all:3.0.4
--- testRuntimeClasspath

我已经找到了selected by rule行,但在我的项目中找不到任何ResolutionStrategy,所以我开始发表评论,看看是什么原因导致了这种情况。事实证明,它是一个插件org.springframework.bootio.spring.dependency-management一起导致该版本降级。为什么?为什么只有当两者都包括在内时?我想这些插件定义了一些ResolutionStrategy?找出ResolutionStrategy来源的最简单方法是什么?

Spring依赖关系管理插件相当复杂。如果您使用--info-i构建项目,您将看到以下日志:

Applying dependency management to configuration 'bootArchives' in project 'demo'
Applying dependency management to configuration 'archives' in project 'demo'
Applying dependency management to configuration 'default' in project 'demo'
Applying dependency management to configuration 'compile' in project 'demo'
Applying dependency management to configuration 'implementation' in project 'demo'
Applying dependency management to configuration 'runtime' in project 'demo'
Applying dependency management to configuration 'compileOnly' in project 'demo'

根据我的经验,依赖管理插件将获胜/迫使自己获胜。

我可以在您的代码片段中看到,您想要3.0.4的Groovy,但Gradle解决了2.5.12。如果查看Spring Boot Dependencies BOM,您会发现2.5.12是Spring Boot 2.3.1的当前版本:https://github.com/spring-projects/spring-boot/blob/2.3.x/spring-boot-project/spring-boot-dependencies/build.gradle#L365..L371

Spring Boot Gradle插件检测是否存在Spring依赖项管理插件,如果存在,则配置该插件以导入Spring Boot依赖项BOM:https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/DependencyManagementPluginAction.java

查看BOM表:https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.3.1.RELEASE/spring-boot-dependencies-2.3.1.RELEASE.pom

您应该能够覆盖Groovy版本,如下所示:

ext {
set("groovy.version", "3.0.4")
}

Spring依赖性管理插件应该接受并应用3.0.4

如果这不能解决你的问题,那么你需要弄清楚其他插件或配置。

我还建议观看Gradle的《管理Spring项目的依赖关系》,了解Spring依赖关系管理插件和Gradle的本地依赖关系管理之间的区别。

最新更新