重复查找器插件的重复资源错误

Var*_*run 5 java spring maven

我有一个由很多子项目组成的项目。考虑三个模块 A、B、C。B 依赖于 A,C 依赖于 A 和 B。 A、B、C 都有一个 test-applicationContext.xml 文件。C 使用 A 和 B 作为 test-jar 依赖项。问题是在编译 C 时,duplicate finder 插件为 test-applicationContext.xml 抛出了重复的资源错误。我试图通过使用<excludes>test-jar 目标上的标签从模块 B 中删除测试资源,但 maven 仍然从测试类目录。我验证了为模块 B 创建的 test-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>
Run Code Online (Sandbox Code Playgroud)

A 有 test-applicationContext.xml 如下:

A ---> src/main/resources/test-applicationContext.xml
Run Code Online (Sandbox Code Playgroud)

而 B 的 xml 如下

B ---> src/test/resources/test-applicationContext.xml
Run Code Online (Sandbox Code Playgroud)

在 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.
Run Code Online (Sandbox Code Playgroud)

我无法重命名这些文件中的任何一个,因为它们是我编写的 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>
Run Code Online (Sandbox Code Playgroud)

我不想从 A 中删除测试资源,因为如果依赖它的模块没有自己的模块,它们就像默认运行的参考资源。

请帮忙!!!!

Rea*_*ted 0

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>
Run Code Online (Sandbox Code Playgroud)

主要警告:假设我正确理解了这里发生的情况,您需要小心不要破坏测试的稳定性。也就是说,如果以下所有条件均为真:

  • 项目 C 有资源Foo.props并且
  • Foo.props项目 A中具有相同的资源test-jar并且
  • 项目 C对 A具有<type>test-jar</type>/依赖性,并且<scope>test</scope>
  • 项目 C 有一个依赖于其自身值的测试Foo.props

Foo.props...那么项目 C 的测试将使用哪个是不可预测的。

如果这不是你关心的问题,或者如果我在这一点上错了,那么我认为这个改变可能会解决你的问题。