Maven:如何覆盖由库添加的依赖关系 [英] Maven: how to override the dependency added by a library

查看:604
本文介绍了Maven:如何覆盖由库添加的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的一般问题:



我的项目P依赖于A,它取决于依赖于D.的版本1.0.1的C。 >

D的版本1.0.1有问题,我想强制使用另一个模块。我不知道如何在我的项目的POM中声明这一点,因为我没有直接添加对D的依赖。这是C声明对D的依赖。



重要提示:在这种情况下,不仅版本被更改,而且组&神器也是。因此,这不仅仅是覆盖依赖关系的版本,而是排除模块并包括另一个模块。



在具体情况下,D是Stax,其1.0.1具有错误。根据bug的说明,通过用stax-api-1.0-2(maven GroupId = javax.xml.stream)替换stax-api-1.0.1(maven GroupId = stax)来解决问题,所以我'/ />

因此,D = stax:stax-api:jar:1.0.1和C = org.apache.xmlbeans:xmlbeans:jar:2.3 .0



我正在使用maven 2.0.9,以防万一重要。



输出mvn依赖关系:树

  mvn依赖: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有以下依赖:



pre> < dependency>
< groupId> org.apache.poi< / groupId>
< artifactId> poi< / artifactId>
< ;版本> 3.6< /版本>
< / dependency>
<依赖关系>
< groupId> org.apache.poi< / groupId>
< artifactId> poi-ooxml< / artifactId>
< version> 3.6< / version>
< / dependency>

提前感谢

解决方案

只需指定当前pom中的版本。


强制版本

版本将如果在当前POM中声明具有特定版本,则始终都将获得荣誉 - 但是,应该注意的是,如果它本身依赖于使用传递依赖关系,这也将影响下游的其他pom。







资源:




Here's my generic problem:

My project P depends on A which depends on B which depends on C which depends on version 1.0.1 of 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.

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.

Thus, D = stax:stax-api:jar:1.0.1 and C = org.apache.xmlbeans:xmlbeans:jar:2.3.0

I'm using maven 2.0.9 in case it matters.

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

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>

Thanks in advance.

解决方案

Simply specify the version in your current pom. The version specified here will override other.

Forcing a version
A version will always be honoured if it is declared in the current POM with a particular version - however, it should be noted that this will also affect other poms downstream if it is itself depended on using transitive dependencies.


Resources :

这篇关于Maven:如何覆盖由库添加的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆