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

usage problem #26

Closed
jb08 opened this issue Apr 9, 2019 · 6 comments
Closed

usage problem #26

jb08 opened this issue Apr 9, 2019 · 6 comments
Labels
question Further information is requested

Comments

@jb08
Copy link

jb08 commented Apr 9, 2019

ran into two issues using errorprone in our project:

Could not find method errorprone() for arguments [build_ddm6vekag2igl3dhoydenrwzg$_run_closure3$_closure7$_closure15@460e695c] on object of type org.gradle.api.tasks.compile.CompileOptions.

This was resolved via:

subprojects {
    apply plugin: 'net.ltgt.errorprone'
}

Second issue:

> Could not resolve all files for configuration ':project-x:annotationProcessor'.
   > Could not find com.google.errorprone:error_prone_core:0.7.1.
     Required by:
         project :project-x
@tbroyer
Copy link
Owner

tbroyer commented Apr 14, 2019

I'm afraid this is Gradle 101 (a plugin applies to a project, and needs to be explicitly applied to a subproject if that's what you want) and dependency management 101 (know where your dependencies are coming from, and where to look for updates; in this case for Error Prone, that would be https://search.maven.org/search?q=g:com.google.errorprone%20AND%20a:error_prone_core&core=gav, vs. https://plugins.gradle.org/plugin/net.ltgt.errorprone for the Gradle plugin).

Moreover, the very first line of the README says:

This plugin configures JavaCompile tasks to use the Error Prone compiler.

with a link that points to Error Prone itself. I couldn't make it clearer (IMO) –in addition to the repository URL, package name, etc.– that this is a third-party project bringing Error Prone (from Google) to Gradle. This is not the only way to use Error Prone with Gradle by the way (I should probably document that somewhere).

@tbroyer tbroyer closed this as completed Apr 14, 2019
@stjj89
Copy link

stjj89 commented May 2, 2019

(Sorry for reviving a closed issue.)

This is not the only way to use Error Prone with Gradle by the way (I should probably document that somewhere).

@tbroyer I would be very interested to learn about alternatives ways to use Gradle with Error Prone. Do you have any ideas or pointers that could lead me in the right direction?

@tbroyer
Copy link
Owner

tbroyer commented May 3, 2019

The simplest way to use Error Prone with Gradle, without any plugin, is (using Kotlin DSL here, adapt if you prefer Groovy):

dependencies {
    annotationProcessor("com.google.errorprone:error_prone_core:2.3.3")
    testAnnotationProcessor("com.google.errorprone:error_prone_core:2.3.3")
}
tasks {
    compileJava {
        options.compilerArgs.addAll(arrayOf("-XDcompilePolicy=simple", "-Xplugin:ErrorProne -XepDisableWarningsInGeneratedCode"))
    }
    testCompileJava {
        options.compilerArgs.addAll(arrayOf("-XDcompilePolicy=simple", "-Xplugin:ErrorProne -XepDisableWarningsInGeneratedCode -XepCompilingTestOnlyCode"))
    }
}

(notice how Error Prone flags are all passed in the same compiler argument, separated by spaces)

To make it work with Java 8, you need to fork the tasks and prepend Error Prone's JavaC to the bootstrap classpath, so this gets hard (I won't show you how to do it here; feel free to look at the plugin's code how it does it)

What this plugin does is:

  • create an errorprone configuration and make all annotationProcessor configurations (from source sets) extend it, so you don't have to add the error_prone_core dependency to all those annotationProcessor configurations
  • setup forking and the bootstrap classpath when running with Java 8
  • add a DSL to make it easier to tweak the Error Prone flags differently depending on tasks (as those flags are all passed in a single string argument; you could do it using Kotlin/Groovy variables and composing the final argument from "snippets", but the DSL makes it easier to reason about)
  • automatically setup -XepCompilingTestOnlyCode for compileTestJava (and similar tasks in Android projects)

@stjj89
Copy link

stjj89 commented May 3, 2019

Thanks for the detailed writeup, @tbroyer. I'm actually trying to get Errorprone to work with Oracle JDK 8 and Gradle.

I'm quite new to working with javac and Gradle, so forgive me if this is a stupid question, but can I confirm that the JDK 8 support that you have implemented essentially replaces the JDK8 javac used by the Gradle with the OpenJDK8-based error-prone-javac specified by errorproneJavac()? I'm running into a bunch of compile errors building my JDK8 codebase with Errorprone enabled, and I'm wondering if it's because of differences between the Oracle JDK8 javac I currently use the and error-prone-javac that I'm replacing it with.

P.S. I'm happy to open another issue to discuss this, if you think that makes more sense.

@tbroyer
Copy link
Owner

tbroyer commented May 3, 2019

the JDK 8 support that you have implemented essentially replaces the JDK8 javac used by the Gradle with the OpenJDK8-based error-prone-javac specified by errorproneJavac()?

Yes.

P.S. I'm happy to open another issue to discuss this, if you think that makes more sense.

This is not specific to Gradle, so feel free to reach out to the ErrorProne Google Group if you have questions.

@stjj89
Copy link

stjj89 commented May 3, 2019

Thanks. That answers my questions for now. I'll be sure to reach out to the ErrorProne Google Group if I have questions about error-prone-javac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants