Search code examples
mavenmaven-resources-plugin

Maven avoid certain files from being copied to test-classes


I'm trying to avoid that certain file types don't end copied in target/test-classes. The code I have right now in my pom file but it's not working is:

<plugin>
 <groupId>org.apache.maven.plugins</groupId>        
  <artifactId>maven-resources-plugin</artifactId>
   <executions>
    <execution>
     <id>default-testResources</id>
      <phase>process-resources</phase>
       <goals>
        <goal>testResources</goal>
       </goals>
       <configuration>                       
        <outputDirectory>
         ${project.build.directory}/test-classes
        </outputDirectory>
        <testResources>
         <testResource>
          <directory>src/test/resources</directory>
          <filtering>true</filtering>                                   
          <excludes>
           <exclude>**/*.nc</exclude>
          </excludes>
        </testResource>
       </testResources>
      </configuration>
     </execution>               
    </executions>
  </plugin>

Solution

  • I was finally able to do what I wanted with:

    <execution>
     <id>default-testResources</id>
     <phase>test-compile</phase>
     <goals>
      <goal>testResources</goal>
     </goals>
     <configuration>
      <resources>
       <resource>
        <directory>${project.basedir}/src/test/resources </directory>
        <excludes>
         <exclude>**/*.nc</exclude>
        </excludes>
       </resource>
      </resources>
     </configuration>
    </execution>
    

    With this code, which is very similar to the one I posted in the question, and by changing the maven version in my eclipse settings from 3.3.3 to 3.3.9 I'm able to avoid the files that I wanted to be copied to target/test-classes