【问题标题】:Duplicate resources error with the duplicate-finder plugin重复查找器插件出现重复资源错误
【发布时间】: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 中删除测试资源,因为它们就像引用资源,如果依赖它的模块没有自己的模块,则默认运行。

请帮忙!!!!

【问题讨论】:

    标签: java spring maven


    【解决方案1】:

    调整maven-duplicate-finder-plugincheckTestClasspath 对你有用吗?我有一个类似的问题,当我添加它时它就消失了:

    <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 对 A 有一个 &lt;type&gt;test-jar&lt;/type&gt; / &lt;scope&gt;test&lt;/scope&gt; 依赖,
    • 项目 C 有一个依赖于 Foo.props 中自己的值的测试

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

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

    【讨论】:

      猜你喜欢
      • 2014-04-06
      • 1970-01-01
      • 2015-10-24
      • 2015-06-13
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多