Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR - patching APIs + auto-patch #38

Open
ZacSweers opened this issue Dec 3, 2019 · 3 comments
Open

FR - patching APIs + auto-patch #38

ZacSweers opened this issue Dec 3, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@ZacSweers
Copy link

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

@tbroyer
Copy link
Owner

tbroyer commented Dec 3, 2019

This is something I had been thinking about for the very first version of this plugin: tbroyer/gradle-errorprone-plugin-v0.0.x#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.

@tbroyer tbroyer added the enhancement New feature or request label Dec 3, 2019
@ZacSweers
Copy link
Author

ZacSweers commented Dec 12, 2019

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()
    }
  }
}

@davidburstrom
Copy link

Looks like it only works if you don't use a -Werror javac argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants