簡體   English   中英

build-helper-maven-plugin add-test-resource錯誤

[英]build-helper-maven-plugin add-test-resource error

我有這個項目結構:

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

test單元測試和it的集成測試。 我正在使用build-helper-maven-plugin將額外的測試源/資源添加到類路徑中,以便以后使用maven-surfire-plugin進行運行unit tests ,使用maven-failsafe-plugin進行integration tests

插件配置如下:

<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>       

這適用於test-sources (它們正確地適應/ target / test-classes)但不復制測試資源 我嘗試了<configuration>不同組合:使用<resource>而不是<directory> ,使用特定文件而不是目錄......但都不起作用。

Stacktrace出錯:

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)

暫時 ,我已經固定它添加集成測試資源到Maven <build>配置:

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

但我更願意在build-helper-maven-plugin下集中所有類路徑修改。 任何人都可以用正確的配置發布示例嗎?

提前致謝。

根據maven-build-helper-plugin的javadoc :add-test-resources resourcesorg.apache.maven.model.Resource的數組。 因此,您必須以這種方式配置它:

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

看看如何配置插件參數

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM