【发布时间】:2015-11-29 22:46:09
【问题描述】:
我有一个由很多子项目组成的项目。考虑三个模块 A、B、C。 B 依赖于 A,C 依赖于 A 和 B。A、B、C 都有一个 test-applicationContext.xml 文件。 C 使用 A 和 B 作为 test-jar 依赖项。问题是重复查找器插件在编译 C 时为 test-applicationContext.xml 引发重复资源错误。我尝试使用 test-jar 目标上的 <excludes> 标记从模块 B 中删除测试资源,但 maven 仍然复制测试类目录中的测试资源。我验证了为模块 B 创建的 test-jar 没有 xml 文件。谁能告诉我哪里出了问题?
A 仅作为测试 jar 打包,而 B 既有主 jar 又有 test-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 中删除测试资源,因为它们就像引用资源,如果依赖它的模块没有自己的模块,则默认运行。
请帮忙!!!!
【问题讨论】: