Maven: excluding java files in compilation

Solution 1:

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>

Solution 2:

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>

Solution 3:

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>