Maven递归依赖性排除

时间:2015-01-09 02:24:55

标签: java maven junit

假设我正在开发依赖于项目B和JUnit-11的项目A.

A -> junit-11 and B

项目B依赖于项目C和JUnit-8。但它已经打包,我无法控制修改其内容。

B -> junit-8  and C

Project C也依赖于jUnit-8。

C -> junit-8

现在,问题是当我尝试构建我的项目(项目A)时,它也会获得jUnit-8,这会破坏编译。在我的pom.xml中定义项目B时,我可以排除项目B对jUnit-8的依赖性,但是它不会传播到项目C的依赖项。结果,jUnit-8仍然被下载并破坏了我的项目。

这是相关的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>

有关如何定义在所有子依赖项中排除jUnit-8的递归排除的任何建议吗?

1 个答案:

答案 0 :(得分:0)

您可能应该在pom.xml中使用Dependency Management