【问题标题】:maven-resources-plugin breaks the resource copy to test-classesmaven-resources-plugin 将资源副本中断为测试类
【发布时间】:2015-03-20 04:51:50
【问题描述】:

通常,我的 POM 文件工作正常,所有单元测试都通过并且所有工件都正确打包。但是,一旦我添加了这个 maven-resources-plugin 以根据配置文件创建特定配置,我的所有测试都会失败,因为 'src/test/resources' 中的任何内容都不会复制到 'test-classes':

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <overwrite>true</overwrite>
                <outputDirectory>${project.build.directory}/${config.dir}/${project.activeProfiles[1].id}</outputDirectory>
                <resources>
                    <filtering>true</filtering>
                    <resource>
                        <directory>src/main/resources</directory>
                    </resource>
                </resources>
            </configuration>
        </plugin>   

我不明白为什么这会阻止复制测试资源。有什么想法吗?

【问题讨论】:

    标签: maven maven-resources-plugin


    【解决方案1】:

    经过多次尝试和错误,我找到了解决方案。需要将 maven-resources-plugin 附加到 process-resources 阶段,以便一切都按预期解决。现在,这可能不是最好的答案,但它对我有用。如果您有更好的解决方案,请告诉我。

    <executions>
      <execution>
         <id>create specific server configuration</id> 
         <phase>process-resources</phase> 
         <goals>
           <goal>resources</goal> 
         </goals>
        <configuration>
        /** as above **/
        </configuration>
      </execution>
    </executions>
    

    【讨论】:

    • 如果这是答案,那么您应该接受它(即使您是问题的作者也可以接受)。
    【解决方案2】:

    我相信你需要添加一些配置:

    <testResources>
        <testResource><directory>src/test/resources</directory></testResource>
    </testResources>
    

    【讨论】:

    • 好点,但是当我简单地删除上面的 maven-resources-plugin 块时,我已经确认按照惯例正确复制了“src/test/resources”。
    • 是的,确实如此。我相信当您包含 maven-resources-plugin 时,您将有义务明确包含此配置以实现您期望和期望的效果。我自己做的,我隐约记得与 Maven 的战斗。
    【解决方案3】:

    问题是您试图将测试资源作为主要资源,而不是测试资源。

    我已经用这段代码完成了:

    <testResources>
     <testResource>
      <directory>src/test/java</directory>
       <filtering>true</filtering>
       <includes><include>**/*.xml</include></includes>
      </testResource>
    </testResources>
    

    【讨论】:

      猜你喜欢
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-18
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多