问题描述
这是我的一般问题:
我的项目 P 依赖于 A 依赖于 B 依赖于 C 依赖于 D 的 1.0.1 版本.
My project P depends on A which depends on B which depends on C which depends on version 1.0.1 of D.
D 的 1.0.1 版本有问题,我想强制使用另一个模块.我不知道如何在我的项目的 POM 中声明它,因为我没有直接添加对 D 的依赖.是 C 声明了对 D 的依赖.
There's a problem with version 1.0.1 of D and I want to force the use of another module. I don't know how to declare this in my project's POMs since I haven't added a dependency on D directly. It's C which declared the dependency on D.
重要提示:在这种情况下,不仅版本改变了,而且组&神器也是.所以这不仅仅是覆盖依赖版本的问题,而是排除一个模块并包含另一个模块的问题.
Important: In this case, not only the version is changed, but the group & artifact as well. So it's not just a matter of overriding the version of the dependency, but rather, of excluding a module and including another one.
在具体情况下,D 是 StAX,其 1.0.1 有一个bug.根据错误中的注释,通过将 stax-api-1.0.1 (maven GroupId = stax) 替换为 stax-api-1.0-2 (maven GroupId = javax.xml.stream)"解决了问题,所以我正在尝试.
In the concrete case, D is StAX whose 1.0.1 has a bug. According to the notes in the bug, "the problems were solved by replacing the stax-api-1.0.1 (maven GroupId = stax) by stax-api-1.0-2 (maven GroupId = javax.xml.stream)" so I'm trying just that.
因此,D = stax:stax-api:jar:1.0.1 和 C = org.apache.xmlbeans:xmlbeans:jar:2.3.0
Thus, D = stax:stax-api:jar:1.0.1 and C = org.apache.xmlbeans:xmlbeans:jar:2.3.0
我正在使用 maven 2.0.9 以防万一.
I'm using maven 2.0.9 in case it matters.
mvn 依赖的输出:tree"
Output of mvn dependency:tree"
mvn dependency:tree
[..snip..]
[INFO] +- org.apache.poi:poi-ooxml:jar:3.6:compile
[INFO] | +- org.apache.poi:poi-ooxml-schemas:jar:3.6:compile
[INFO] | | +- org.apache.xmlbeans:xmlbeans:jar:2.3.0:compile
[INFO] | | | - stax:stax-api:jar:1.0.1:compile
在我项目的 POM 中,我对A"有以下依赖:
In my project's POM I have the following dependency on "A":
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.6</version>
</dependency>
提前致谢.
推荐答案
只需在当前 pom.xml 中指定版本即可.此处指定的版本将覆盖其他版本.
Simply specify the version in your current pom. The version specified here will override other.
强制一个版本
如果在当前 POM 中以特定版本声明某个版本,则该版本将始终受到尊重 - 但是,应该注意,如果它本身依赖于使用传递依赖项,这也会影响下游的其他 pom.
资源:
这篇关于Maven:如何覆盖库添加的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!