使用duplicate-finder插件重复资源错误

时间:2015-09-03 23:11:37

标签: java spring maven

我有一个由很多子项目组成的项目。考虑三个模块A,B,C。 B依赖于A和C依赖于A和B.A,B,C都有一个test-applicationContext.xml文件。 C使用A和B作为测试jar依赖项。问题是重复的finder插件在编译C时抛出了test-applicationContext.xml的重复资源错误。我试图通过使用test-jar目标上的<excludes>标记从模块B中删除测试资源但是maven仍然是副本来自test-classes目录的测试资源。我验证了为模块B创建的测试jar没有xml文件。有人能说出什么问题吗?

A仅作为测试罐包装,而B既有主罐也有测试罐目标。 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中删除测试资源,因为它们就像默认情况下运行的参考资源,如果依赖它的模块没有自己的模块。

请帮助!!!!

1 个答案:

答案 0 :(得分:0)

调整maven-duplicate-finder-plugin&#39; 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对A,
  • <type>test-jar</type> / <scope>test</scope>依赖关系
  • 项目C的测试依赖于Foo.props
  • 中自己的值

...然后它是不可预测的,Foo.props将由项目C的测试使用。

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

相关问题