javamavenmaven-compiler-plugin

How to use custom execution for testCompile goal for maven-compiler-plugin


I am using an annotationProcessor with maven-compiler-plugin in a custom profile.

<profile>                                                       
  <id>error-prone-test-compile</id>                             
  <build>                                                       
    <plugins>                                                   
      <plugin>                                                  
        <groupId>org.apache.maven.plugins</groupId>             
        <artifactId>maven-compiler-plugin</artifactId>          
        <version>3.10.1</version>                               
        <executions>                                            
          <execution>                                           
            <id>test-compile-error-prone</id>                   
            <phase>test-compile</phase>                         
            <goals>                                             
              <goal>testCompile</goal>                          
            </goals>                                            
            <configuration>                                     
              <failOnError>false</failOnError>                  
              <source>${java.version}</source>                  
              <target>${java.version}</target>                  
              <compilerArgs>                                    
                <arg>-Xpkginfo:always</arg>                     
                <arg>-XDcompilePolicy=simple</arg>              
                <arg>                                           
                  -Xplugin:ErrorProne \                         
                  -XepExcludedPaths:.*[\\/]resources[\\/].*     
                </arg>                                          
              </compilerArgs>                                   
              <annotationProcessorPaths>                        
                <path>                                          
                  <groupId>com.google.errorprone</groupId>      
                  <artifactId>error_prone_core</artifactId>     
                  <version>${error-prone.version}</version>     
                </path>                                         
              </annotationProcessorPaths>                       
            </configuration>                                    
          </execution>                                          
        </executions>                                           
      </plugin>                                                 
    </plugins>                                                  
  </build>                                                      
</profile>                                                      

Not using the current config, when running

mvn clean test-compile -Perror-prone-test-compile

the testCompile goal is executed twice (default-testCompile and test-compile-error-prone):

[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ checkstyle ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2945 source files to /home/vyom/IdeaProjects/checkstyle/target/test-classes
[INFO] /home/vyom/IdeaProjects/checkstyle/src/test/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/InputRegexpSemantic12.java: Some input files use or override a deprecated API.
[INFO] /home/vyom/IdeaProjects/checkstyle/src/test/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/InputRegexpSemantic12.java: Recompile with -Xlint:deprecation for details.
[INFO] /home/vyom/IdeaProjects/checkstyle/src/test/java/com/puppycrawl/tools/checkstyle/internal/utils/TestUtil.java: Some input files use unchecked or unsafe operations.
[INFO] /home/vyom/IdeaProjects/checkstyle/src/test/java/com/puppycrawl/tools/checkstyle/internal/utils/TestUtil.java: Recompile with -Xlint:unchecked for details.
[INFO] 
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (test-compile-error-prone) @ checkstyle ---
[INFO] Changes detected - recompiling the module!

I want to replace default-testCompile with test-compile-error-prone i.e. only execute test-compile-error-prone and not execute default-testCompile.

Is there any way to achieve this?


Solution

  • Skip the default-testCompile:

      <execution>                                           
        <id>default-testCompile</id>
        <phase>test-compile</phase>
        <goals>
            <goal>testCompile</goal>
        </goals>                   
    
        <configuration>                                     
          <skip>true</skip>
        </configuration>
      </execution>                  
      <execution>                                           
        <id>test-compile-error-prone</id>                   
        <phase>test-compile</phase>                         
        <goals>                                             
          <goal>testCompile</goal>                          
        </goals>                                            
        <configuration>                                     
          <failOnError>false</failOnError>