melix / jmh-gradle-plugin

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

JmhBytecodeGenerator is incompatible with any module-info stuff #222

Open cpw opened 2 years ago

cpw commented 2 years ago

Describe the bug You're using JmhBytecodeGenerator, which seems to have been pretty much abandoned upstream and is completely incompatible with any module-info related artifacts.

To Reproduce Steps to reproduce the behavior:

  1. Specify a module-info in any jmh related artifact to be processed by gradle plugin
  2. Try and run
  3. See error
    
     ./gradlew jmh

Configure project : Version: 5.0.7

Task :jmhRunBytecodeGenerator FAILED Processing 6 classes from /home/cpw/projects/minecraft/eventbus/build/classes/java/jmh with "reflection" generator Writing out Java source to /home/cpw/projects/minecraft/eventbus/build/jmh-generated-sources and resources to /home/cpw/projects/minecraft/eventbus/build/jmh-generated-resources Exception in thread "main" java.lang.NoClassDefFoundError: module-info is not a class because access_flag ACC_MODULE is set at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010) at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855) at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:573) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:466) at org.openjdk.jmh.generators.bytecode.JmhBytecodeGenerator.main(JmhBytecodeGenerator.java:90)

FAILURE: Build failed with an exception.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 743ms 4 actionable tasks: 1 executed, 3 up-to-date


I've tried the asm generator, but that has similar difficulties

./gradlew jmh

Configure project : Version: 5.0.7

Task :jmhRunBytecodeGenerator FAILED Processing 6 classes from /home/cpw/projects/minecraft/eventbus/build/classes/java/jmh with "asm" generator Writing out Java source to /home/cpw/projects/minecraft/eventbus/build/jmh-generated-sources and resources to /home/cpw/projects/minecraft/eventbus/build/jmh-generated-resources Exception in thread "main" java.lang.UnsupportedOperationException: Module requires ASM6 at org.objectweb.asm.ClassVisitor.visitModule(ClassVisitor.java:145) at org.objectweb.asm.ClassReader.readModuleAttributes(ClassReader.java:781) at org.objectweb.asm.ClassReader.accept(ClassReader.java:580) at org.objectweb.asm.ClassReader.accept(ClassReader.java:424) at org.openjdk.jmh.generators.asm.ASMGeneratorSource.processClass(ASMGeneratorSource.java:60) at org.openjdk.jmh.generators.asm.ASMGeneratorSource.processClass(ASMGeneratorSource.java:53) at org.openjdk.jmh.generators.asm.ASMGeneratorSource.processClasses(ASMGeneratorSource.java:47) at org.openjdk.jmh.generators.bytecode.JmhBytecodeGenerator.main(JmhBytecodeGenerator.java:81)

FAILURE: Build failed with an exception.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 721ms 4 actionable tasks: 1 executed, 3 up-to-date



Looking upstream it seems this particular generator (bytecode) is not getting a lot of attention and hasn't for some time. The only focus is in the annotation processor, which you seem to have specifically abandoned.

I can't figure out any way to change to using the annotation processor with the gradle plugin sadly.