21

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!

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
easyrider
  • 361
  • 2
  • 4
  • 14
  • What is the exact path for jsfunit files (relative to `${basedir}`)? – Pascal Thivent Jun 12 '10 at 12:13
  • src/main/java/de/hska/repo/ui/jsfunit – easyrider Jun 12 '10 at 12:15
  • 1
    I don't understand. `compiler:testCompile` *compiles application test sources* (i.e. test sources under `src/test/main`) so there is nothing to exclude. What is the problem exactly? What are you trying to solve? – Pascal Thivent Jun 12 '10 at 12:51
  • Hmm.. you are right. My problem is: jsfunit uses junit3, but our junit tests use junit4. in pom.xml i can't include junit3 and junit4 dependencies and if i try to run junit tests the compiler fails to compile files from jsfunit/package 'cause there only junit4 in classpath(but not junit3) – easyrider Jun 12 '10 at 12:59
  • but i need the classes from jsfunit package if i run tomcat:run goal – easyrider Jun 12 '10 at 13:00
  • Also keep in mind that the path doesn't have to include `src/test/java`. See http://stackoverflow.com/a/19713000/239408 – xverges Jan 23 '15 at 15:35
  • A superb description about your issue can be found here. http://stackoverflow.com/questions/2593588/maven-skip-building-test-classes[here](http://stackoverflow.com/questions/2593588/maven-skip-building-test-classes) – Anant Laxmikant Bobde Oct 17 '16 at 08:29

1 Answers1

38

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>
samskivert
  • 3,694
  • 20
  • 22