简体   繁体   English

Maven递归依赖性排除

[英]Maven recursive dependency exclusion

Let's say I am developing project A that depends on project B and JUnit-11. 假设我正在开发依赖于项目B和JUnit-11的项目A.

A -> junit-11 and B

Project B depends on project C and JUnit-8. 项目B依赖于项目C和JUnit-8。 but it is already packaged and I have no control over modifying its content. 但它已经打包,我无法控制修改其内容。

B -> junit-8  and C

Project C has dependency on jUnit-8 as well. 项目C也依赖于jUnit-8。

C -> junit-8

Now, the problem is when I try build my project (project A), it also gets jUnit-8 which breaks the compilation. 现在,问题是当我尝试构建我的项目(项目A)时,它也会获得jUnit-8,这会破坏编译。 I can exclude the dependency of project B on jUnit-8 when defining that in my pom.xml but that does not propagates to the dependency of project C. As a result, jUnit-8 is still downloaded and breaks my project. 在我的pom.xml中定义项目B时,我可以排除项目B对jUnit-8的依赖性,但是它不会传播到项目C的依赖项。结果,jUnit-8仍然被下载并破坏了我的项目。

here are the related pom.xml: 这是相关的pom.xml:

Project A (My Project) :pom.xml:
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>

    <dependency>
        <groupId>B</groupId>
        <artifactId>B</artifactId>
        <version>1.0</version>
        <exclusion>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>       
        </exclusion>

    </dependency>
</dependencies>

Project B (Existing project):pom.xml:
<dependencies>
       <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8</version>
        </dependency>
       <dependency>
            <groupId>C</groupId>
            <artifactId>C</artifactId>
            <version>1.0</version>
        </dependency>
</dependencies>

Project C (Existing project):pom.xml:
<dependencies>
       <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8</version>
        </dependency>
</dependencies>

Any advice on how to define a recursive exclusion that excludes jUnit-8 in all sub-dependencies? 关于如何定义在所有子依赖项中排除jUnit-8的递归排除的任何建议?

您可能应该在pom.xml中使用依赖关系管理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM