maven-compiler-plugin排除

时间:2010-06-12 12:08:03

标签: compilation maven-2

我有以下问题。 我想在测试 - 编译阶段排除一些.java文件(** / jsfunit / * .java),另一方面我想在编译阶段包含它们(id我用tomcat启动tomcat:运行目标)

我的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>

但它不起作用:default-testCompile中的exclude不会过滤这些类。 如果我删除了注释,那么所有匹配的类** / jsfunit / * .java都会被编译,但只有触摸它们才会被编译!

1 个答案:

答案 0 :(得分:30)

要从default-testCompile阶段排除文件,您必须使用<testExcludes>。所以上面的例子看起来像这样:

<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>