我有一个包含很多子项目的项目。考虑三个模块 A、B、C。 B 依赖于 A,C 依赖于 A 和 B。A、B、C 各有一个 test-applicationContext.xml 文件。 C 使用 A 和 B 作为测试 jar 依赖项。问题是重复查找器插件在编译 C 时为 test-applicationContext.xml 抛出重复资源错误。我尝试使用 <excludes>
从模块 B 中删除测试资源。标记在 test-jar 目标上,但 maven 仍然从 test-classes 目录复制测试资源。我确认为模块 B 创建的测试 jar 没有 xml 文件。谁能告诉我哪里出了问题?
A 仅打包为测试 jar,而 B 既有主 jar 又有测试 jar 目标。 C的pom文件如下:
<dependency>
<groupId>my.project</groupId>
<artifactId>A</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>my.project</groupId>
<artifactId>B</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
A 有 test-applicationContext.xml 如下:
A ---> src/main/resources/test-applicationContext.xml
而 B 有如下 xml
B ---> src/test/resources/test-applicationContext.xml
在 C 上执行 mvn install 时出现以下错误
[WARNING] Found duplicate and different resources in [my.project:B:jar:tests, my.project:A]:
[WARNING] test-applicationContext.xml
[WARNING] Found duplicate classes/resources in test classpath.
我无法重命名这些文件中的任何一个,因为它们是我编写的 spring 配置类中的引用。我也将此添加到 B:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<excludes>
<exclude>*.xml</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
我不想从 A 中删除测试资源,因为它们就像引用资源,如果依赖它的模块没有自己的引用资源,则默认运行。
请帮忙!!!!
最佳答案
会调整 maven-duplicate-finder-plugin
的 checkTestClasspath
为你工作?我有一个类似的问题,当我添加它时它就消失了:
<plugin>
<groupId>com.ning.maven.plugins</groupId>
<artifactId>maven-duplicate-finder-plugin</artifactId>
<version>...</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<failBuildInCaseOfConflict>true</failBuildInCaseOfConflict>
<checkTestClasspath>false</checkTestClasspath>
<ignoredResources>
...
</ignoredResources>
</configuration>
</plugin>
主要警告:假设我理解这里发生的事情是正确的,您需要小心不要破坏测试的稳定性。也就是说,如果以下所有为真:
- 项目 C 有一个资源
Foo.props
、和 - 项目 A 具有相同的资源
Foo.props
在其test-jar
、和 - 项目 C 有一个
<type>test-jar</type>
/<scope>test</scope>
对 A、和 的依赖
- 项目 C 有一个测试依赖于它自己在
Foo.props
中的值
...那么它是不可预测的 Foo.props
将被项目 C 的测试使用。
如果这不是您关心的问题,或者如果我在这一点上错了,那么我认为此更改可能会解决您的问题。
关于java - 重复查找器插件出现重复资源错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32386816/