melix/jmh-gradle-plugin

ErrorProne compatibility issue

sergeykad opened this issue · 6 comments

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 commented

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

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 commented

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 commented

@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 commented

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