Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven-compiler-plugin exclude

I have a following problem. I would like to exclude some .java files (**/jsfunit/*.java) during the test-compile phase and on the other side I would like to include them during the compile phase (id i start tomcat with tomcat:run goal)

My pom.xml

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                 <!-- <excludes>
                     <exclude>**/*JSFIntegration*.java</exclude>
                 </excludes> -->                    
            </configuration>
           <executions>
           <!-- <execution>
                        <id>default-compile</id>
                        <phase>compile</phase>
                        <goals>
                          <goal>compile</goal>
                        </goals>
                        <configuration>
                            <includes>
                                 <include>**/jsfunit/*.java</include>
                            </includes>
                        </configuration>
               </execution>-->
              <execution>
                        <id>default-testCompile</id>
                        <phase>test-compile</phase>
                        <configuration>
                            <excludes>
                                <exclude>**/jsfunit/*.java</exclude>
                            </excludes>
                        </configuration> 
                        <goals>

                <goal>testCompile</goal>
                        </goals>
                </execution>                  
             </executions>

        </plugin>

But it does not work : exclude in default-testCompile execution does not filter these classes. If I remove the comments then all classes matched **/jsfunit/*.java would be compiled but only if I touch them!

like image 906
easyrider Avatar asked Jun 12 '10 12:06

easyrider


People also ask

How do you exclude a jar file while building a application?

To exclude any file from a jar / target directory you can use the <excludes> tag in your pom.

How do I exclude a jar from pom?

We can have multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependencies we want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom.

What does mvn clean command do?

Thus, when mvn clean command executes, Maven deletes the build directory. We can customize this behavior by mentioning goals in any of the above phases of clean life cycle.

Which plugin is used to copy filter include and exclude non Java files into your final project in Maven?

Apache Maven Resources Plugin – Including and excluding files and directories.


1 Answers

To exclude files from the default-testCompile phase, you have to use <testExcludes>. So your example above would look like so:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
  <executions>
    <execution>
      <id>default-testCompile</id>
      <phase>test-compile</phase>
      <configuration>
        <testExcludes>
          <exclude>**/jsfunit/*.java</exclude>
        </testExcludes>
      </configuration> 
      <goals>
        <goal>testCompile</goal>
      </goals>
    </execution>                  
  </executions>
</plugin>
like image 199
samskivert Avatar answered Sep 29 '22 12:09

samskivert