tbroyer / gradle-errorprone-plugin

Gradle plugin to use the error-prone compiler for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Android Integration

realbarisbasturk opened this issue · comments

Hi,

I am trying to integrate error prone into an Android SDK. Error prone don't have an official Gradle support and recommends this plugin instead. However, Android support is removed in 3.0+ according to the release notes. Release notes also states that the plugin should still be usable after a manual configuration of Java compile task.

The closest thing I could find on how to do this is here #26 (comment). The solution provided works for me but I am a bit worried that the compiler argument (-XDcompilePolicy=simple) might cause issues at runtime and not sure if it is safe to use as is. I am trying to decide whether to proceed with the solution in the comment or not integrate error prone at all.

Thank you.

From the README:

  • “This plugin creates a configuration named errorprone, and configures the <sourceSet>AnnotationProcessor configuration for each source set to extend it.” → the source sets with AGP aren't the same, so no configuration is configured to extend the errorprone configuration
  • “Note that this plugin only enables Error Prone on tasks for source sets” → again, no source set so Error Prone is disabled

So you'd want to follow the “If you're creating custom compile tasks, then you'll have to configure them manually to enable Error Prone” instructions then, or equivalent (AGP creates its own JavaCompile tasks, unrelated to source sets, so considered "custom" here). That's what is meant by "manual configuration" in the 3.0 release notes.

Wrt the -XDcompilePolicy=simple compiler argument, that's what the plugin configures anyway; but it shouldn't have any impact on the produced classes (you can verify this by compiling with and without that argument or Error Prone: the .class files should be exactly the same).

Fwiw, the reason that Android support was removed from the plugin is that AGP actively makes it hard to configure tasks directly, and get the tasks associated with each variant. As I don't build for Android myself, and more and more Android projects use Kotlin anyway, trying to maintain that best-effort support wasn't a good use of my time.