【发布时间】: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 的递归排除的任何建议?
【问题讨论】:
-
在
<scope>test</scope>中声明的 junit 依赖项是不寻常的。 -
好吧,它们是用测试范围声明的,但我在这里删除了它以简化。此外,其他一些不限于测试范围的依赖项也存在类似问题。