Monday, 5 August 2013

Error Prone compiler with Apache Maven Compiler plugin

Update 11 Sep 2013: All plexus-compiler released!
Because you usually write code very fast, you can sometimes made mistakes.
To prevent some stupid errors, folks from Google write the error prone compiler.
Have a look at the various detected patterns (yeah definitely more interesting than checkstyle :P )
Kudos to Alex Eagle for the contribution!.
The configuration to use it:
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.1</version>
  <configuration>
    <compilerId>javac-with-errorprone</compilerId>
    <forceJavacCompilerUse>true</forceJavacCompilerUse>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-compiler-javac-errorprone</artifactId>
      <version>2.3</version>
    </dependency>
    <!-- NOTE this one will not be needed when plexus-compiler-javac-errorprone and error-prone will be released -->
    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-compiler-javac</artifactId>
      <version>2.3</version>
    </dependency>
  </dependencies>
</plugin>
Feel free to test, I hope we will be able to have released versions of those artifacts soon.

1 comment:

Alex Eagle said...

I tried this out and there were a couple changes needed to the instructions. I updated the docs on the error-prone wiki in case anyone else is giving this a try:

https://code.google.com/p/error-prone/wiki/InstallingErrorProne#Maven