such as add some compile arguments when I run "mvn compile", maybe sometimes I just want to use jdk to compile my project.
Hello!
I think the easiest way to control this in Maven is to use a maven profile to wrap the error prone configuration:
<profiles>
<profile>
<id>errorprone</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<!-- maven-compiler-plugin defaults to targeting Java 5, but our javac
only supports >=6 -->
<source>7</source>
<target>7</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
<version>2.8</version>
</dependency>
<!-- override plexus-compiler-javac-errorprone's dependency on
Error Prone with the latest version -->
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.0.14</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Then run:
mvn clean compile -perrorprone to activate the profile from the command line. The clean is needed because if maven sees up-to-date compiled artifacts from the last non-errorprone build, then it won't attempt a recompile.
It works very well, thank you so much! And my command line is "mvn clean compile -P errorprone".
Most helpful comment
It works very well, thank you so much! And my command line is "mvn clean compile -P errorprone".