【问题标题】:Maven recursive dependency exclusionMaven递归依赖排除
【发布时间】:2015-03-07 07:44:55
【问题描述】:

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

A -> junit-11 and B

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

B -> junit-8  and C

项目 C 也依赖于 jUnit-8。

C -> junit-8

现在,问题是当我尝试构建我的项目(项目 A)时,它也会得到 jUnit-8,这会破坏编译。在我的 pom.xml 中定义项目 B 对 jUnit-8 的依赖项时,我可以排除项目 B 的依赖项,但这不会传播到项目 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 的递归排除的任何建议?

【问题讨论】:

  • 在 &lt;scope&gt;test&lt;/scope&gt; 中声明的 junit 依赖项是不寻常的。
  • 好吧,它们是用测试范围声明的,但我在这里删除了它以简化。此外,其他一些不限于测试范围的依赖项也存在类似问题。

标签: java maven junit


【解决方案1】:

也许你应该在你的 pom.xml 中使用Dependency Management

【讨论】:

  • 您可能想要突出显示允许排除的依赖管理的特定功能。
猜你喜欢
  • 2019-10-29
  • 2021-10-24
  • 1970-01-01
  • 2018-07-06
  • 2017-09-14
  • 2016-04-20
  • 2012-02-25
  • 2015-04-12
相关资源
最近更新 更多