idea-jmh-plugin: Scala: Unable to find the resource: /META-INF/BenchmarkList

idea ultimate 14.1.2 + scala plugin 1.4.15 + jmh plugin 1.0.1

I have an sbt project opened in IDEA. When I run one benchmark method or all methods in a class I get this error:

Exception in thread "main" java.lang.RuntimeException: ERROR: Unable to find the resource: /META-INF/BenchmarkList
    at org.openjdk.jmh.runner.AbstractResourceReader.getReaders(AbstractResourceReader.java:96)
    at org.openjdk.jmh.runner.BenchmarkList.find(BenchmarkList.java:104)
    at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:250)
    at org.openjdk.jmh.runner.Runner.run(Runner.java:202)
    at org.openjdk.jmh.Main.main(Main.java:69)

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 22
  • Comments: 26 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Hi!

Do you have org.openjdk.jmh:jmh-generator-annprocess on your classpath? If yes, is annotation processing enabled in your IDE? You can find the checkbox under Preferences -> Build, Execution, Deployment -> Compiler -> Annotation Processors

The solution for me was to use testAnnotationProcessor in Gradle 6 build.gradle:

	testImplementation 'org.openjdk.jmh:jmh-core:1.25'
	testAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.25'

instead of

	testImplementation 'org.openjdk.jmh:jmh-core:1.25'
	testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.25'

Mind that my setup is a bit non-standard - I run JMH from JUnit. Still, this solved missing BenchmarkList problem.

Also I don’t use jmh-gradle-plugin, only those two dependencies from above are enough to integrate JMH to JUnit.

If you’re using the jmh-gradle-plugin you just need to have all of the following in your dependencies block:

    jmh 'org.openjdk.jmh:jmh-core:1.34'
    jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.34'

    // this is the line that solved it for me
    jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.34'

Then I was able to run the test from within the IDE (I’m using IntelliJ).

The solution for me was to use testAnnotationProcessor in Gradle 6 build.gradle:

	testImplementation 'org.openjdk.jmh:jmh-core:1.25'
	testAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.25'

instead of

	testImplementation 'org.openjdk.jmh:jmh-core:1.25'
	testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.25'

Mind that my setup is a bit non-standard - I run JMH from JUnit. Still, this solved missing BenchmarkList problem.

Also I don’t use jmh-gradle-plugin, only those two dependencies from above are enough to integrate JMH to JUnit.

Seconding this, changing to testAnnotationProcessor worked for me to fix the same issue.

Adding dependency “org.openjdk.jmh:jmh-generator-annprocess” solved an issue for me.

It seems like sometimes I can get this to work, but I’m not sure what I have been doing that is making it work. Just a minute ago, I ran ./gradlew --stacktrace jmh and it failed, and then I just ran it again after adding --info and it worked. I also set verbosity = 'EXTRA', although I’m not certain when I did that. I’ve seen this happen a few times, where it just works a few times in a row, and then it starts getting this error again, without any changes.

I also notice that when I searched for BenchmarkList again, I found it in additional places:

% ls -lt $(find . -name BenchmarkList)
-rwx------+ 1 dk068x Domain Users 304 Nov 15 14:34 ./build/jmh-generated-classes/META-INF/BenchmarkList*
-rwx------+ 1 dk068x Domain Users 304 Nov 15 14:34 ./build/classes/java/jmh/META-INF/BenchmarkList*
-rwx------+ 1 dk068x Domain Users 304 Nov 15 14:34 ./build/classes/java/main/META-INF/BenchmarkList*

I then re-ran the same command and it worked again.

I am using IntelliJ IDEA Ultimate with a plain old Java Module (no Maven or Gradle). I downloaded the JHM suite as a dependency, I made sure that all of the above suggestions are done on my side. Most importantly:

  • I have the dependencies
  • I have the right classpath
  • Annotation Processors are enabled

Tried building, compiling, cleaning, running, changing the configuration, running again with no luck.

Then I added the fully qualified name of the annotation processor that has to run, and it worked: org.openjdk.jmh.generators.BenchmarkProcessor

You do this under: Build, Execution, Deployment > Compiler > Annotation Processors (see screenshot).

I wonder if you want to add some business logic to the module to not just offer to enable AP, but also add the FQN?

image

I added this to my build.gradle and solved the problem, I can run from IntelliJ

annotationProcessor  'org.openjdk.jmh:jmh-core:1.34'
annotationProcessor  'org.openjdk.jmh:jmh-generator-annprocess:1.34'

I am seeing this problem, and I can’t find a workaround.

Here is my build.gradle:

apply plugin: 'java'

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.5"
    }
}

apply plugin: "me.champeau.gradle.jmh"

repositories {
    jcenter()
}

dependencies {
    testCompile 'junit:junit:4.12'

    jmh "org.openjdk.jmh:jmh-core:$jmhVersion"
    compile "org.openjdk.jmh:jmh-generator-bytecode:$jmhVersion"
    //compile "org.openjdk.jmh:jmh-generator-annprocess:$jmhVersion"
    
    compile "com.jayway.jsonpath:json-path:2.2.0"
    compile "commons-io:commons-io:2.5"
    compile "org.apache.commons:commons-lang3:3.5"
    compile "commons-lang:commons-lang:2.6"
    compile "javax.validation:validation-api:1.1.0.Final"
    compile "com.fasterxml.jackson.core:jackson-databind:2.8.7"
    compile "com.google.code.gson:gson:2.8.0"
    
    jmh "commons-io:commons-io:2.5"
    jmh "commons-lang:commons-lang:2.6"
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.3'
}

jmh {
    //verbosity = 'EXTRA' // Verbosity mode. Available modes are: [SILENT, NORMAL, EXTRA]
    jvmArgs = ['-Djmh.ignoreLock=true']
    jmhVersion = '1.19'
    fork = 2
    duplicateClassesStrategy = 'warn'
}

sourceSets {
    main {
        java {
            srcDirs = ['src/main/java', 'src/jmh/java']
        }
    }
}

Here’s the output when I run, forcing tasks to run:

% ./gradlew --rerun-tasks jmh
:compileJava
:processResources
:classes
:compileTestJava NO-SOURCE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
:compileJmhJava
:processJmhResources NO-SOURCE
:jmhClasses
:jmhRunBytecodeGenerator
Processing 3 classes from C:\Users\dk068x\workspace\jsonpathexperiments\build\classes\java\jmh with "reflection" generator
Writing out Java source to C:\Users\dk068x\workspace\jsonpathexperiments\build\jmh-generated-sources and resources to C:\Users\dk068x\workspace\jsonpathexperiments\build\jmh-generated-classes
:jmhCompileGeneratedClasses
:jmhJar
Encountered duplicate path "enums/Enums$Thingie1.class" during copy operation configured with DuplicatesStrategy.WARN
Encountered duplicate path "enums/Enums$Thingie2.class" during copy operation configured with DuplicatesStrategy.WARN
Encountered duplicate path "enums/Enums.class" during copy operation configured with DuplicatesStrategy.WARN
:jmh FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jmh'.
> A failure occurred while executing me.champeau.gradle.IsolatedRunner
   > ERROR: Unable to find the resource: /META-INF/BenchmarkList

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s
7 actionable tasks: 7 executed

I see the raw file at:

./build/jmh-generated-classes/META-INF/BenchmarkList

Here’s an elided listing of the jar contents:

     0 Wed Nov 15 13:52:26 PST 2017 META-INF/
    59 Wed Nov 15 13:26:34 PST 2017 META-INF/MANIFEST.MF
     0 Wed Nov 15 13:52:26 PST 2017 enums/
  1852 Wed Nov 15 13:52:26 PST 2017 enums/Enums$Thingie1.class
  2082 Wed Nov 15 13:52:26 PST 2017 enums/Enums$Thingie2.class
  1139 Wed Nov 15 13:52:26 PST 2017 enums/Enums.class
  1852 Wed Nov 15 13:52:26 PST 2017 enums/Enums$Thingie1.class
  2082 Wed Nov 15 13:52:26 PST 2017 enums/Enums$Thingie2.class
  1139 Wed Nov 15 13:52:26 PST 2017 enums/Enums.class
     0 Wed Nov 15 13:52:26 PST 2017 enums/generated/
 13478 Wed Nov 15 13:52:26 PST 2017 enums/generated/Enums_enumValuesLoop_jmhTest.class
 13466 Wed Nov 15 13:52:26 PST 2017 enums/generated/Enums_enumValuesMap_jmhTest.class
   312 Wed Nov 15 13:52:26 PST 2017 enums/generated/Enums_jmhType.class
  4144 Wed Nov 15 13:52:26 PST 2017 enums/generated/Enums_jmhType_B1.class
  1306 Wed Nov 15 13:52:26 PST 2017 enums/generated/Enums_jmhType_B2.class
  4165 Wed Nov 15 13:52:26 PST 2017 enums/generated/Enums_jmhType_B3.class
   304 Wed Nov 15 13:52:26 PST 2017 META-INF/BenchmarkList
   214 Wed Nov 15 13:52:26 PST 2017 META-INF/CompilerHints
314932 Fri Nov 03 08:35:32 PDT 2017 junit-4.12.jar
 18541 Fri Nov 03 08:36:48 PDT 2017 jmh-generator-bytecode-1.19.jar
 31558 Fri Nov 03 08:36:48 PDT 2017 jmh-generator-asm-1.19.jar
 24291 Fri Nov 03 08:36:48 PDT 2017 jmh-generator-reflection-1.19.jar
502355 Fri Nov 03 08:36:44 PDT 2017 jmh-core-1.19.jar

What can I do to resolve this?

Seems like you have an inner module devicegraph-benchmarks and outer devicegraph. When jmh configuration is created outer module is chosen automatically, but it doesn’t have dependency on annprocess. Currently I would suggest adding this dependency if it does not cause too much problem to you, but in general I should implement choosing the module in run configuration. I’ll do my best, but still not sure that will find time for that quite soon.