gradle-errorprone-plugin
gradle-errorprone-plugin copied to clipboard
FR - patching APIs + auto-patch
http://errorprone.info/docs/patching
It would be great if this could be something enabled via invocation property, such as -PautoPatch and have the plugin manage the arguments + application of the generated patch
This is something I had been thinking about for the very first version of this plugin: https://github.com/tbroyer/gradle-errorprone-plugin-v0.0.x/issues/65
One thing is sure, I wouldn't use a project property or system property. I had been thinking about specific tasks (using @Option), or simply exposing a configurable property and letting users bind it to a property of their choice.
For the time being, please experiment in your own build scripts (things should be doable in less than 30 lines of Groovy/Kotlin Gradle DSL), and we can see later whether and how to integrate it into the plugin.
Actually I think this doesn't need anything from the library if you use IN_PLACE. We're doing this now and it worked like a charm
/**
* Adds common configuration for error prone on projects. Note that this still uses application of the error prone
* plugin as an opt-in marker for now, and is not applied to every project.
*/
private fun Project.configureErrorProne() {
pluginManager.onPlugin("net.ltgt.errorprone") {
dependencies.add("errorprone", "com.google.errorprone:error_prone_core:$ERROR_PRONE_VERSION")
if (!Jvm.current().javaVersion!!.isJava9Compatible) {
dependencies.add("errorproneJavac", "com.google.errorprone:javac:9+181-r4173-1")
}
val javaCompileConfigurer = {
tasks.withType<JavaCompile>().onConfigureEach {
options.errorprone(actionOf {
disableWarningsInGeneratedCode.set(true)
if (project.hasProperty("epAutoPatch")) {
// Always log this verbosely
logger.lifecycle("Enabling error-prone auto-patching on ${project.path}:$name")
errorproneArgs.addAll(
"-XepPatchChecks:MissingOverride,DefaultCharset,DeadException,MutableConstantField,MethodCanBeStatic",
"-XepPatchLocation:IN_PLACE"
)
}
})
}
}
if (isAndroidProject) {
afterEvaluate {
javaCompileConfigurer()
}
} else {
javaCompileConfigurer()
}
}
}
Looks like it only works if you don't use a -Werror javac argument.