7

Normally, my POM file is working fine and all unit tests pass and all artifacts are packaged properly. However, once I've added this maven-resources-plugin to create specific configuration depending upon profile all my tests fail because nothing in 'src/test/resources' is copied to '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>   

I don't understand why this would block the copying of test resources. Any ideas?

TemarV
  • 317
  • 1
  • 4
  • 12

3 Answers3

2

I believe you need to add some configuration:

<testResources>
    <testResource><directory>src/test/resources</directory></testResource>
</testResources>
unigeek
  • 2,656
  • 27
  • 27
  • Good point, but I already confirmed that 'src/test/resources' is copied properly by convention when I simply remove the maven-resources-plugin block above. – TemarV Jan 21 '15 at 16:04
  • 1
    Yes, true enough. I believe when you include the maven-resources-plugin, however you will be obligated to explicitly include this configuration to achieve the effect you expect and desire. I do it myself and I vaguely recall fighting the battle with Maven. – unigeek Jan 21 '15 at 16:07
2

After much trial and error, I came to a solution. The maven-resources-plugin needed to be attached to the process-resources phase in order for everything to resolve as expected. Now, this may not be the best answer, but it worked for me. Let me know if you have a better solution.

<executions>
  <execution>
     <id>create specific server configuration</id> 
     <phase>process-resources</phase> 
     <goals>
       <goal>resources</goal> 
     </goals>
    <configuration>
    /** as above **/
    </configuration>
  </execution>
</executions>
TemarV
  • 317
  • 1
  • 4
  • 12
1

The problem is you are trying to get your test resources as main resources, not test resources.

I've done it with this code:

<testResources>
 <testResource>
  <directory>src/test/java</directory>
   <filtering>true</filtering>
   <includes><include>**/*.xml</include></includes>
  </testResource>
</testResources>
Johann
  • 447
  • 4
  • 12