Maven: excluding java files in compilation

前端 未结 5 983
甜味超标
甜味超标 2020-12-01 00:41

I have a folder of java sources which I wish to exclude from the compilation.

My folder is under qa/apitests/src/main/java/api/test/omi.

I added

相关标签:
5条回答
  • 2020-12-01 01:03

    If you want to exclude the java sources from compiling, then mention them in the Maven Compiler Plugin definition

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

    The resources plugin only defines what all resources to bundle in your final artifact.

    0 讨论(0)
  • 2020-12-01 01:05

    For anyone needing to exclude test sources <exclude> tag will not work. You need to use <testExclude> instead:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <testExcludes>
            <testExclude>**/PrefixToExclude*</testExclude>
          </testExcludes>
        </configuration>
      </plugin>
    
    0 讨论(0)
  • 2020-12-01 01:16

    The top voted answer works fine but it doesn't allow forcing the exclusion when the excluded class/classes is/are being used by not-excluded ones.

    Workaround using 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>
    
    0 讨论(0)
  • 2020-12-01 01:20

    Adding an exclude as the other answers suggested worked for me, except the path shouldn't include "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>
    
    0 讨论(0)
  • 2020-12-01 01:28

    Use the Maven Compiler Plugin.

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <excludes>
          <exclude>**/api/test/omi/*.java</exclude>
        </excludes>
      </configuration>
    </plugin>
    
    0 讨论(0)
提交回复
热议问题