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

ErrorProne compatibility issue #248

Open
sergeykad opened this issue May 18, 2023 · 6 comments
Open

ErrorProne compatibility issue #248

sergeykad opened this issue May 18, 2023 · 6 comments

Comments

@sergeykad
Copy link

Describe the bug
jmhCompileGeneratedClasses task fails with error: plug-in not found: ErrorProne message. There is a similar issue described here: tbroyer/gradle-errorprone-plugin#19

To Reproduce
Steps to reproduce the behavior:

  1. Add
plugins {
   id "me.champeau.jmh" version "0.7.1"
   id "net.ltgt.errorprone" version "3.1.0"
}
  1. Run jmhCompileGeneratedClasses task
  2. Gradle reports the following:
> Task :services:jmhCompileGeneratedClasses FAILED
82 actionable tasks: 1 executed, 81 up-to-date
error: plug-in not found: ErrorProne

FAILURE: Build failed with an exception.
@vlsi
Copy link

vlsi commented May 28, 2023

The workaround is

tasks.jmhCompileGeneratedClasses {
    // See https://github.com/melix/jmh-gradle-plugin/issues/248
    options.annotationProcessorPath = configurations.jmhAnnotationProcessor.get()
    options.errorprone {
        // JMH generates duplicate field names like byte p000, p001, p002
        disable("HidingField")
    }
}

See

private static TaskProvider<JavaCompile> createJmhCompileGeneratedClassesTask(Project project,
Provider<Directory> jmhGeneratedSourcesDir,
Provider<Directory> jmhGeneratedClassesDir,
JmhParameters extension,
JavaPluginExtension java,
JavaToolchainService toolchainService) {
project.tasks.register(JMH_TASK_COMPILE_GENERATED_CLASSES_NAME, JavaCompile) {
it.group = JMH_GROUP
it.dependsOn 'jmhRunBytecodeGenerator'
it.classpath = project.sourceSets.jmh.runtimeClasspath
if (extension.includeTests.get()) {
it.classpath += project.sourceSets.test.output + project.sourceSets.test.runtimeClasspath
}
it.source(jmhGeneratedSourcesDir)
it.destinationDirectory.set(jmhGeneratedClassesDir)
it.javaCompiler.convention(toolchainService.compilerFor(java.toolchain))
}

@sergeykad
Copy link
Author

Thanks, @vlsi .

Actually adding the jmhAnnotationProcessor configuration to the classpath fixed the error: plug-in not found: ErrorProne issue. I disabled error-prone anyway since I do not want to run it on the generated classes.

I also had to add jmhAnnotationProcessor 'org.apiguardian:apiguardian-api:1.1.2' , but I am not sure if it is related.

In any case, I think at least part of these changes should be merged into the plugin.

@melix
Copy link
Owner

melix commented May 30, 2023

In any case, I think at least part of these changes should be merged into the plugin.

I am not convinced they should. Gradle properly isolates annotation processor dependencies from compile dependencies. The fact that you have to add the annotation processor classes to the compile classpath either means that error prone mixes its annotations with its processor, or that there is a bug in the error prone plugin. In both cases the fix should be on error prone.

@vlsi
Copy link

vlsi commented May 30, 2023

@melix , JMH_TASK_COMPILE_GENERATED_CLASSES_NAME is jmh-gradle-plugin-specific task that does not account for annotation processors.

I believe error-prone-gradle-plugin properly adds dependencies to jmhAnnotationProcessor configuration, however, I do not see where jmh-gradle-plugin picks up the annotation processor configuration and passes it to jmhCompileGeneratedClasses task.

Does it make sense?

@vlsi
Copy link

vlsi commented May 30, 2023

So a better workaround is

tasks.jmhCompileGeneratedClasses {
    options.annotationProcessorPath = configurations.jmhAnnotationProcessor.get()
}

plugins.withId("net.ltgt.errorprone") {
    tasks.jmhCompileGeneratedClasses {
        options.errorprone {
            // JMH generates duplicate field names like byte p000, p001, p002
            disable("HidingField")
        }
    }
}

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

No branches or pull requests

3 participants