19

I have this project structure:

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

test for unit tests and it for integration tests. I'm using build-helper-maven-plugin to add additional test sources/resources to the classpath for later use maven-surfire-plugin for run unit tests and maven-failsafe-plugin for 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.

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:

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

Thanks in advance.

1 Answer 1

32

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

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

Take a look at how to configure plugin parameters.

3
  • sorry I think I must be missing something but the code shown in the answer seems to be same as in the question. I only mention it because I am getting the same error as reported in the question but have the configuration shown in the answer.
    – robbie70
    Apr 11, 2019 at 14:28
  • @robbie70 the configuration has a slight difference. In my question the path is configuration/resources/directory while in the answer is configuration/resources/resource/directory
    – troig
    Apr 15, 2019 at 7:26
  • 1
    ah yes apologies my mistake...thanks for clarifying
    – robbie70
    Apr 15, 2019 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.