melix / jmh-gradle-plugin

Integrates the JMH benchmarking framework with Gradle
Apache License 2.0
676 stars 87 forks source link

ErrorProne compatibility issue #248

Open sergeykad opened 1 year ago

sergeykad commented 1 year ago

Describe the bug jmhCompileGeneratedClasses task fails with error: plug-in not found: ErrorProne message. There is a similar issue described here: https://github.com/tbroyer/gradle-errorprone-plugin/issues/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"
    }
  2. Run jmhCompileGeneratedClasses task
  3. 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 1 year ago

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 https://github.com/melix/jmh-gradle-plugin/blob/d7974cfbc6421747c39f1c3d8afa23a9ee1c0176/src/main/groovy/me/champeau/jmh/JMHPlugin.groovy#L151-L168

sergeykad commented 1 year ago

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 1 year ago

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 1 year ago

@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 1 year ago

I guess jmh-gradle-plugin needs something like https://github.com/gradle/gradle/blob/b32b8efd354fbad9921ac5801f86d04ec376a07d/subprojects/plugins/src/main/java/org/gradle/api/plugins/JavaBasePlugin.java#L201, see https://github.com/gradle/gradle/blob/b32b8efd354fbad9921ac5801f86d04ec376a07d/subprojects/plugins/src/main/java/org/gradle/api/plugins/internal/JvmPluginsHelper.java#L87-L92

vlsi commented 1 year ago

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