Maven依赖项在传递依赖项中忽略了管理版本 [英] Maven dependencyManagement version ignored in transitive dependencies
问题描述
即使我有< dependencyManagement>,Maven仍在过渡性地引入版本16的番石榴.指定版本18的部分.
Maven is transitively pulling in version 16 of guava, even though I have a <dependencyManagement> section which specifies version 18.
快速摘要:
-
gwizard-example
取决于gwizard-config
-
gwizard-config
有一个父pom,gwizard-parent
-
gwizard-parent
具有< dependencyManagement>它指定了番石榴的版本18
gwizard-example
depends ongwizard-config
gwizard-config
has a parent pom,gwizard-parent
gwizard-parent
has <dependencyManagement> which specifies version 18 of guava
非常感谢,这是一个开源项目,因此您可以直接看到poms: gwizard-parent , gwizard-config , gwizard-example .但是,这是gwizard-parent
中的重要部分:
Thankfully this is an opensource project, so you can see the poms directly: gwizard-parent, gwizard-config, gwizard-example. However, here's the important bit in gwizard-parent
:
<properties>
<guava.version>18.0</guava.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
...以及在gwizard-example中声明的简洁装饰:
...and the no-frills dependency declared in gwizard-example:
<properties>
<gwizard.version>0.5</gwizard.version>
</properties>
<dependencies>
<dependency>
<groupId>org.gwizard</groupId>
<artifactId>gwizard-config</artifactId>
<version>${gwizard.version}</version>
</dependency>
</dependencies>
gwizard-config的依赖关系树正确显示了番石榴18:
The dependency tree for gwizard-config shows guava 18 correctly:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ gwizard-config ---
[INFO] org.gwizard:gwizard-config:jar:0.5
[INFO] +- com.google.inject:guice:jar:4.0-beta5:compile
[INFO] | \- com.google.guava:guava:jar:18.0:compile
但是,gwizard-example的依赖关系树显示了番石榴16(这会导致问题):
However, the dependency tree for gwizard-example shows guava 16 (which causes problems):
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ gwizard-example ---
[INFO] org.gwizard:gwizard-example:jar:1.0-SNAPSHOT
[INFO] +- org.gwizard:gwizard-config:jar:0.5:compile
[INFO] | +- com.google.inject:guice:jar:4.0-beta5:compile
[INFO] | | \- com.google.guava:guava:jar:16.0.1:compile
这是使用Maven v3.2.5.我感到莫名其妙.帮助吗?
This is using Maven v3.2.5. I am baffled. Help?
可能与之相关:忽略了父级中的dependencyManagement
更新:github上链接的poms正在更改;在gwizard-example
中添加对gwizard-services
的依赖关系(直接声明一个番石榴dep)可以解决此问题.这里仍然存在某种不良的底层行为.
UPDATE: The poms linked on github are changing; adding a dependency to gwizard-services
(which directly declares a guava dep) in gwizard-example
"fixed" the problem. There's still some sort of bad underlying behavior here.
更新:创建了此JIRA问题
推荐答案
有一件简单的事情. dependencyManagement
不会声明真正使用的依赖关系,它只是定义可以使用的版本等.
There is a simple thing. A dependencyManagement
does not declare a dependency which is really used it's only defining versions etc. which can be used.
如果您定义这样的内容,则不会导致更改.
If you define something like this it will not result in a change.
<properties>
<guava.version>18.0</guava.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
如果您真的想覆盖树中使用的版本,则需要定义一个真正的依赖项: 因此,根据以上定义,您还需要添加以下内容:
If you really like to overwrite the version which is used in you tree you need to define a real dependency: So based on the above definition you need to add the following as well:
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
如果添加了此内容,请稍后通过mvn dependency:tree
检查.
If you have added this please check afterwards via mvn dependency:tree
.
这篇关于Maven依赖项在传递依赖项中忽略了管理版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!