java build-helper-maven-plugin add-test-resource 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26337866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 09:45:19  来源:igfitidea点击:

build-helper-maven-plugin add-test-resource error

javamavenintegration-testingmaven-pluginbuild-helper-maven-plugin

提问by troig

I have this project structure:

我有这个项目结构:

/src
    /main
        /java
        /resources
    /test 
        /java
        /resources
    /it
        /java
        /resources

testfor unit tests and itfor integration tests. I'm using build-helper-maven-pluginto add additional test sources/resources to the classpath for later use maven-surfire-pluginfor run unit testsand maven-failsafe-pluginfor integration tests.

test用于单元测试和it集成测试。我正在使用build-helper-maven-plugin将额外的测试源/资源添加到类路径中,以便以后使用maven-surfire-plugin运行 unit testsmaven-failsafe-plugin用于integration tests.

Plugin config as belows:

插件配置如下:

<plugin>                                                         
   <groupId>org.codehaus.mojo</groupId>                          
   <artifactId>build-helper-maven-plugin</artifactId>      
   <version>1.9.1</version>      
   <executions>                                                  
      <execution>                                                
         <id>add-integration-test-sources</id>                   
         <phase>generate-test-sources</phase>                    
         <goals>                                                 
            <goal>add-test-source</goal>                         
         </goals>                                                
         <configuration>                                         
            <sources>                                            
               <source>src/it/java</source>                      
            </sources>                                           
         </configuration>                                        
      </execution>                                               
      <execution>                                                
         <id>add-integration-test-resources</id>                 
         <phase>generate-test-resources</phase>                  
         <goals>                                                 
            <goal>add-test-resource</goal>                       
         </goals>                                                
         <configuration>                                         
            <resources>                                          
               <directory>/src/it/resources</directory>
            </resources>                                         
         </configuration>                                        
      </execution>                                               
   </executions>                                                 
</plugin>       

This works fine for the test-sources(they are coppied correctly to /target/test-classes) but doesn't copy test-resources. I've tried different combinations of <configuration>: use <resource>instead <directory>, use an specific file instead a directory...but neither works.

这适用于test-sources(它们被正确复制到 /target/test-classes)但不复制test-resources。我尝试了不同的组合<configuration>:使用<resource>代替<directory>,使用特定文件代替目录......但都不起作用。

Stacktrace with the error:

有错误的堆栈跟踪:

Caused by: org.apache.maven.plugin.PluginConfigurationException: Unable to parse configuration of mojo org.codehaus.mojo:build-helper-maven-plugin:1.9.1:add-test-resource for parameter directory: Cannot configure instance of org.apache.maven.model.Resource from src/it/resources
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:597)
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:529)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:92)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)

PROVISIONALLY, I've fixed it adding the integration tests resources to maven <build>configuration:

暂时,我已经修复了它,将集成测试资源添加到 Maven<build>配置中:

<build>
...
    <testResources>                               
       <testResource>                             
          <directory>src/it/resources</directory> 
       </testResource>                            
    </testResources>    
</build>

But I would prefer to have centralized all classpath modifications under build-helper-maven-plugin. Can anyone post example with a correct config?

但我更愿意将所有类路径修改集中在build-helper-maven-plugin. 任何人都可以发布具有正确配置的示例吗?

Thanks in advance.

提前致谢。

回答by René Link

According to the javadoc of the maven-build-helper-plugin:add-test-resources. The resourcesis an array of org.apache.maven.model.Resource. Thus you must configure it this way:

根据maven-build-helper-plugin:add-test-resources的 javadoc 。的resources是阵列org.apache.maven.model.Resource。因此,您必须以这种方式配置它:

<configuration>
    <resources>  
         <resource>                                     
               <directory>/src/it/resources</directory>
         </resource>
    </resources>      
</configuration>

Take a look at how to configure plugin parameters.

看看如何配置插件参数