melix / jmh-gradle-plugin

Integrates the JMH benchmarking framework with Gradle
Apache License 2.0
662 stars 88 forks source link

"jmhJar" task creates invalid jar #168

Open Noricc opened 4 years ago

Noricc commented 4 years ago

Describe the bug I want to create a fat jar with jmhJar because my benchmarks require to load some data from a file, the jmh task runs the benchmarks in another directory, which prevents loading data with a relative path.

./gradlew jmhJar succeeds but running the jar with java -jar build/libs/<jar-name>.jar fails with the following exception

Exception in thread "main" java.lang.NoClassDefFoundError: joptsimple/OptionException
    at org.openjdk.jmh.Main.main(Main.java:41)
Caused by: java.lang.ClassNotFoundException: joptsimple.OptionException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 1 more

I used the shadowJar plugin, as indicated by the documentation. gradle shadowJar works, but it builds the main application.

I also tried with gradle 5.5 and the plugin version 0.5.0, but then gradle jmh failed with the following error

Error: Could not find or load main class org.openjdk.jmh.runner.ForkedMain
Caused by: java.lang.ClassNotFoundException: org.openjdk.jmh.runner.ForkedMain

My understanding of the gradle DSL is limited, so here is a link to my build.gradle.