加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 02:09:27 所属栏目:Java 来源:网络整理
导读:我有一个由很多子项目组成的项目.考虑三个模块A,B,C. B依赖于A和C依赖于A和B.A,C都有一个test-applicationContext.xml文件. C使用A和B作为测试jar依赖项.问题是重复的finder插件在编译C时抛出了test-applicationContext.xml的重复资源错误.我试图通过使用 ex
我有一个由很多子项目组成的项目.考虑三个模块A,B,C. B依赖于A和C依赖于A和B.A,C都有一个test-applicationContext.xml文件. C使用A和B作为测试jar依赖项.问题是重复的finder插件在编译C时抛出了test-applicationContext.xml的重复资源错误.我试图通过使用< excludes>从模块B中删除测试资源.在test-jar目标上标记,但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中删除测试资源,因为它们就像默认情况下运行的参考资源,如果依赖它的模块没有自己的模块.

请帮忙!!!!

解决方法

会调整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在其test-jar中具有相同的资源Foo.props
>项目C有一个< type> test-jar< / type> /< scope> test< / scope>依赖于A和
>项目C有一个依赖于Foo.props中自己的值的测试

…然后,项目C的测试将使用哪些Foo.props是不可预测的.

如果这不是你的问题,或者我在这一点上错了,那么我认为这种改变可以解决你的问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读