maven-compiler-plugin exclude
Asked Answered
C

1

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!

Cowcatcher answered 12/6, 2010 at 12:8 Comment(7)
What is the exact path for jsfunit files (relative to ${basedir})?Myosin
src/main/java/de/hska/repo/ui/jsfunitCowcatcher
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?Myosin
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)Cowcatcher
but i need the classes from jsfunit package if i run tomcat:run goalCowcatcher
Also keep in mind that the path doesn't have to include src/test/java. See https://mcmap.net/q/225997/-maven-excluding-java-files-in-compilationCentrepiece
A superb description about your issue can be found here. #2594088hereRoslyn
C
39

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>
Chryso answered 7/9, 2010 at 6:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.