-
Notifications
You must be signed in to change notification settings - Fork 168
Using Error Prone with Buck and OkBuck
This page describes how OkBuck users can configure Buck to use Error Prone.
Using Error Prone on JDK 8 requires compiling with the Error Prone javac compiler. (If you are on JDK 11 or higher, you do not need to use Error Prone javac.) To use this compiler with Buck, follow these steps:
- Download javac-9+181-r4173-1.jar.
- Run
tooling/errorprone/createtinyjavaxtools.sh
to create atinyjavaxtools.jar
that contains key classes that need to be in Buck's bootclasspath. Usage:
createtinyjavaxtools.sh path/to/javac-9+181-r4173-1.jar
This creates tinyjavaxtools.jar
in the directory from which it is run.
- Add the following to your
.buckconfig
file to use the Error Prone javac:
[tools]
javac_jar = path/to/javac-9+181-r4173-1.jar
- Add
-Xbootclasspath/p:path/to/tinyjavaxtools.jar
to your.buckjavaargs
file to placetinyjavaxtools.jar
in the Buck bootclasspath.
Once you complete these steps, Buck Java builds will compile with the Error Prone javac, and you are ready to enable Error Prone.
To enable Error Prone in Buck builds add the following to your Gradle configuration for the relevant modules:
dependencies {
// use appropriate Error Prone version
annotationProcessor 'com.google.errorprone:error_prone_core:2.3.3'
}
compileJava {
options.compilerArgs << '-XDcompilePolicy=simple'
// Any Error Prone config options should come immediately after -Xplugin:ErrorProne
options.compilerArgs << '-Xplugin:ErrorProne -Xep:RemoveUnusedImports:ERROR'
}
With this configuration, Error Prone will run in the Buck build. To handle Android builds you can use tasks.withType(JavaCompile)
rather than compileJava
. Alternately, for greater flexibility you can configure Error Prone compiler arguments inside your Buck configuration (e.g., in custom DEFS
), though this won't be synced back to the Gradle build.
At this point, OkBuck does not have integrated support for the Gradle Error Prone plugin, the best way to use Error Prone with Gradle. The instructions above enable Error Prone with Buck builds, but Gradle builds on JDK 8 will break, since Error Prone javac is not being used. To fix Gradle builds, you can add configuration like this to fork Java builds and add the Error Prone javac to the boot classpath.