58

我有一个希望从编译中排除的 java 源文件夹。

我的文件夹在qa/apitests/src/main/java/api/test/omi.

我在下面添加了以下条目,pom.xmlqa/bamtests没有帮助。我还需要做一个条目吗?

   <build>
     <resources>
       <resource>
         <directory>src/main/java</directory>
         <includes>
           <include>**/*.properties</include>
           <include>**/*.xml</include>
           <include>**/*.xsd</include>
           <include>**/*.csv</include>
         </includes>
         <excludes>
<exclude>src/main/java/api/test/omi</exclude>
         </excludes>
       </resource>
</build>
4

5 回答 5

70

使用Maven 编译器插件

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <excludes>
      <exclude>**/api/test/omi/*.java</exclude>
    </excludes>
  </configuration>
</plugin>
于 2013-07-29T10:07:59.587 回答
46

添加一个排除项,因为建议的其他答案对我有用,但路径不应包含“src/main/java”:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <excludes>
          <exclude>com/filosync/store/StoreMain.java</exclude>
        </excludes>
      </configuration>
    </plugin>
  </plugins>
</build>
于 2013-10-31T17:26:44.737 回答
33

对于任何需要排除测试源 <exclude>标签的人都不起作用。您需要<testExclude>改用:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
      <testExcludes>
        <testExclude>**/PrefixToExclude*</testExclude>
      </testExcludes>
    </configuration>
  </plugin>
于 2015-09-11T20:03:08.780 回答
2

如果要从编译中排除 java 源,请在Maven 编译器插件定义中提及它们

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
            <excludes>
              <exclude>src/main/java/api/test/omi/*.java</exclude>
            </excludes>
        </configuration>
    </plugin>
</plugins>

资源插件仅定义要在最终工件中捆绑的所有资源。

于 2013-07-29T10:08:54.773 回答
2

投票最多的答案可以正常工作,但当排除的类/类被非排除的类/正在使用时,它不允许强制排除。

解决方法maven-antrun-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>process-classes</phase>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <tasks>
            <delete dir="target/classes/folder/to/exclude"/>
        </tasks>
    </configuration>
</plugin>
于 2016-05-09T00:06:24.300 回答