为什么 Gradle 会降级我在 Grails 3.1 应用程序中的传递依赖项?
Why does Gradle downgrade my transitive dependencies in a Grails 3.1 application?
我的 grails-flyway
插件的传递依赖性有问题。 org.grails.plugins:grails-flyway:0.2.1
声明对 org.flywaydb:flyway-core:4.0.1
的依赖。当我将插件包含到我的 Grails 3.1.6 项目中时 Gradle 将 Flyway 降级到版本 3.2.1。
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
我的 Gradle 构建文件如下所示
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:${assetPipelinePluginVersion}"
classpath "org.grails.plugins:hibernate5:5.0.5"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
}
}
version "0.40.15"
group "zsc.supporter"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
apply plugin: "org.grails.grails-doc"
apply plugin: "asset-pipeline"
apply plugin: 'com.github.ben-manes.versions'
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
repositories {
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://dl.bintray.com/saw303/plugins" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-ehcache"
console "org.grails:grails-console"
profile "org.grails.profiles:web:3.1.6"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:${assetPipelinePluginVersion}"
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.52.0"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.21"
compile "org.grails.plugins:spring-security-core:3.0.4"
compile "org.grails.plugins:quartz:2.0.8"
compile "org.grails.plugins:mail:2.0.0.RC4"
compile "eu.bitwalker:UserAgentUtils:1.18"
compile 'org.mnode.ical4j:ical4j:1.0.7'
compile 'org.grails.plugins:browser-detection:3.1.0'
compile "com.googlecode.libphonenumber:libphonenumber:7.3.1"
runtime 'org.grails.plugins:grails-flyway:0.2.1'
testCompile "org.grails.plugins:grails-wizer:0.3"
testCompile 'org.grails:grails-datastore-test-support:5.0.5.RELEASE'
runtime 'mysql:mysql-connector-java:5.1.29'
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
目前我不明白为什么 Gradle 会降低我的传递依赖性。有人可以提供吗?
我知道我可以在 build.gradle
中强制使用 flyway-core:4.0.1
依赖项,但我想了解降级的原因。
UPDATE-1
当我 运行 gradle dependencies | grep flyway
我得到以下输出。
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
请在 pastebin. The grails-flyway
plugin and its pom.xml can be found at Bintray 找到完整的输出。
UPDATE-2
我试图强制Gradle根据Gradles Reference使用org.flywaydb:flyway-core:4.0.1
。
configurations.all {
resolutionStrategy.force 'org.flywaydb:flyway-core:4.0.1'
}
这不影响问题。依赖树仍然使用flyway-core
.
的3.2.1版本
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
UPDATE-3
Gradles dependencyInsight
命令
gradle dependencyInsight --dependency flyway-core --configuration runtime
结果
:dependencyInsight
org.flywaydb:flyway-core:3.2.1 (selected by rule)
org.flywaydb:flyway-core:4.0.1 -> 3.2.1
\--- org.grails.plugins:grails-flyway:0.2.1
\--- runtime
(selected by rule)
是什么意思?
"Solution" - 或者如何解决
我找不到导致 Gradle 使用 flyway-core:3.2.1
而不是 flyway-core:4.0.1
的规则。但我找到了解决该问题的方法。
我将以下内容添加到我的 build.gradle
中以修改我的 Gradle runtime
解析策略。
configurations.runtime.resolutionStrategy {
eachDependency { DependencyResolveDetails det ->
if (det.requested.name == 'flyway-core' && det.requested.group == 'org.flywaydb') {
det.useVersion(det.requested.version)
}
}
}
造成它的原因是 spring-boot-dependencies-1.3.3.RELEASE.pom
这将 flyway 版本强制为 3.2.1
根据 Spring Boot docs,您应该可以在 build.gradle
中添加这样一行:
ext['flyway.version'] = '4.0.1'
转到您的 Gradle 缓存文件夹:
cd ~/.gradle/caches/modules-2/files-2.1
搜索此版本号:
grep -r "3.2.1" *
你会发现哪个pom文件正在使用这个版本,
通常是 spring-boot-dependencies-x.y.z.RELEASE.pom
中的内容:
<flyway.version>3.2.1</flyway.version>
......
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
</dependency>
也就是说,如果你使用spring-boot
,它会覆盖一些依赖版本。
您可以通过在 gradle.properties
文件中添加以下行来再次覆盖它:
flyway.version=4.0.1
我遇到了类似的问题,浪费了几个小时。
所以我在这里留下了这些信息,希望这可以在你遇到这个问题时节省你的时间
我的 grails-flyway
插件的传递依赖性有问题。 org.grails.plugins:grails-flyway:0.2.1
声明对 org.flywaydb:flyway-core:4.0.1
的依赖。当我将插件包含到我的 Grails 3.1.6 项目中时 Gradle 将 Flyway 降级到版本 3.2.1。
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
我的 Gradle 构建文件如下所示
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:${assetPipelinePluginVersion}"
classpath "org.grails.plugins:hibernate5:5.0.5"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
}
}
version "0.40.15"
group "zsc.supporter"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
apply plugin: "org.grails.grails-doc"
apply plugin: "asset-pipeline"
apply plugin: 'com.github.ben-manes.versions'
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
repositories {
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://dl.bintray.com/saw303/plugins" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-ehcache"
console "org.grails:grails-console"
profile "org.grails.profiles:web:3.1.6"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:${assetPipelinePluginVersion}"
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.52.0"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.21"
compile "org.grails.plugins:spring-security-core:3.0.4"
compile "org.grails.plugins:quartz:2.0.8"
compile "org.grails.plugins:mail:2.0.0.RC4"
compile "eu.bitwalker:UserAgentUtils:1.18"
compile 'org.mnode.ical4j:ical4j:1.0.7'
compile 'org.grails.plugins:browser-detection:3.1.0'
compile "com.googlecode.libphonenumber:libphonenumber:7.3.1"
runtime 'org.grails.plugins:grails-flyway:0.2.1'
testCompile "org.grails.plugins:grails-wizer:0.3"
testCompile 'org.grails:grails-datastore-test-support:5.0.5.RELEASE'
runtime 'mysql:mysql-connector-java:5.1.29'
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
目前我不明白为什么 Gradle 会降低我的传递依赖性。有人可以提供吗?
我知道我可以在 build.gradle
中强制使用 flyway-core:4.0.1
依赖项,但我想了解降级的原因。
UPDATE-1
当我 运行 gradle dependencies | grep flyway
我得到以下输出。
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
请在 pastebin. The grails-flyway
plugin and its pom.xml can be found at Bintray 找到完整的输出。
UPDATE-2
我试图强制Gradle根据Gradles Reference使用org.flywaydb:flyway-core:4.0.1
。
configurations.all {
resolutionStrategy.force 'org.flywaydb:flyway-core:4.0.1'
}
这不影响问题。依赖树仍然使用flyway-core
.
+--- org.grails.plugins:grails-flyway:0.2.1
| \--- org.flywaydb:flyway-core:4.0.1 -> 3.2.1
UPDATE-3
Gradles dependencyInsight
命令
gradle dependencyInsight --dependency flyway-core --configuration runtime
结果
:dependencyInsight
org.flywaydb:flyway-core:3.2.1 (selected by rule)
org.flywaydb:flyway-core:4.0.1 -> 3.2.1
\--- org.grails.plugins:grails-flyway:0.2.1
\--- runtime
(selected by rule)
是什么意思?
"Solution" - 或者如何解决
我找不到导致 Gradle 使用 flyway-core:3.2.1
而不是 flyway-core:4.0.1
的规则。但我找到了解决该问题的方法。
我将以下内容添加到我的 build.gradle
中以修改我的 Gradle runtime
解析策略。
configurations.runtime.resolutionStrategy {
eachDependency { DependencyResolveDetails det ->
if (det.requested.name == 'flyway-core' && det.requested.group == 'org.flywaydb') {
det.useVersion(det.requested.version)
}
}
}
造成它的原因是 spring-boot-dependencies-1.3.3.RELEASE.pom
这将 flyway 版本强制为 3.2.1
根据 Spring Boot docs,您应该可以在 build.gradle
中添加这样一行:
ext['flyway.version'] = '4.0.1'
转到您的 Gradle 缓存文件夹:
cd ~/.gradle/caches/modules-2/files-2.1
搜索此版本号:
grep -r "3.2.1" *
你会发现哪个pom文件正在使用这个版本,
通常是 spring-boot-dependencies-x.y.z.RELEASE.pom
中的内容:
<flyway.version>3.2.1</flyway.version>
......
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
</dependency>
也就是说,如果你使用spring-boot
,它会覆盖一些依赖版本。
您可以通过在 gradle.properties
文件中添加以下行来再次覆盖它:
flyway.version=4.0.1
我遇到了类似的问题,浪费了几个小时。 所以我在这里留下了这些信息,希望这可以在你遇到这个问题时节省你的时间