Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala: Unable to find the resource: /META-INF/BenchmarkList #13

Open
epishkin opened this issue Apr 23, 2015 · 28 comments
Open

Scala: Unable to find the resource: /META-INF/BenchmarkList #13

epishkin opened this issue Apr 23, 2015 · 28 comments

Comments

@epishkin
Copy link

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)
@artyushov
Copy link
Owner

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

@epishkin
Copy link
Author

Here is the command from the Run console. jmh-generator-annprocess is not there.

/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/bin/java \
-Dfile.encoding=UTF-8 \
-classpath \
/Users/oiepishkin/projects/tapad/service-devicegraph/benchmarks/target/scala-2.10/classes:\
SKIPPED_SEVERAL_SCREENS_OF_JARS:\
/Users/oiepishkin/.ivy2/cache/org.openjdk.jmh/jmh-core/jars/jmh-core-1.6.jar:\
/Users/oiepishkin/.ivy2/cache/org.openjdk.jmh/jmh-generator-asm/jars/jmh-generator-asm-1.6.jar:\
/Users/oiepishkin/.ivy2/cache/org.openjdk.jmh/jmh-generator-bytecode/jars/jmh-generator-bytecode-1.6.jar:\
/Users/oiepishkin/.ivy2/cache/org.openjdk.jmh/jmh-generator-reflection/jars/jmh-generator-reflection-1.6.jar:\
/Users/oiepishkin/.ivy2/cache/org.ow2.asm/asm/jars/asm-5.0.3.jar \
org.openjdk.jmh.Main com.tapad.devicegraph.CompressionBench.*

Even after I added jmh-generator-annprocess to my sbt module dependencies (it's multi module sbt project) it doesn't appear in the jmh plugin command's classpath. Here is the benchmarks sbt module definition

//project/Build.scala
object DeviceGraphBuild {
  //skipped the rest of my sbt project defs
  lazy val benchmarks: Project = Project(
    "devicegraph-benchmarks",
    file("benchmarks"),
    settings = BuildSettings ++ pl.project13.scala.sbt.SbtJmh.jmhSettings ++ Seq(
      libraryDependencies ++= Seq(
        "org.openjdk.jmh" % "jmh-generator-annprocess" % "1.8" //required for jmh IDEA plugin. Make sure this version matches sbt-jmh version!
      )
    )
  )
}

project/plugins.sbt

addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.1.14")

I have a jmh-generator-annprocess in my benchmarks module dependencies
screen shot 2015-04-23 at 2 23 44 pm

In the jmh run configuration it's no possible to choose which IDEA module classpath to use. Could this be the cause of this problem? Run configuration dialogs for ScalaTest and JUnit have that option.

JMH run configuration
screen shot 2015-04-23 at 2 20 15 pm

ScalaTest run configuration with Use classpath and SDK of module
screen shot 2015-04-23 at 2 21 40 pm

The annotation processing is enabled
screen shot 2015-04-23 at 2 28 59 pm

@epishkin
Copy link
Author

IDEA/scala/jmh plugins don't generate benchmarks/target/scala-2.10/classes/META-INF/BenchmarkList file. When I run sbt-jmh this file is created

sbt
project devicegraph-benchmarks
run -i 3 -wi 3 -f1 .*CompressionBench.*

After running jmh from console/sbt I can run my benchmarks from IDEA. But once I do Build - Rebuild META-INF/BenchmarkList file is deleted and jmh plugin doesn't create it in my IDEA.

I have a workaround to run jmh from sbt once and them run benchmarks from IDEA. Not sure if it's the correct way and all modified source files will be enhanced by jmh IDEA plugin.
screen shot 2015-04-23 at 3 29 39 pm

@artyushov
Copy link
Owner

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.

@kennethjor
Copy link

I'm having a similar issue wanting to run jmh in a subproject. @artyushov could you explain the proposed workaround?

I tried adding the jmh plugin and dependencies to the root project instead and run the jmh task from Gradle, but no luck.

@pranasblk
Copy link

pranasblk commented Apr 18, 2016

I got

Exception in thread "main" java.lang.RuntimeException: ERROR: Unable to find the resource: /META-INF/BenchmarkList

After upgrade of IntelliJ plugin from 1.0.1 to 1.0.2
IDEA 15.0.5

Gradle Plugin:

'me.champeau.gradle:jmh-gradle-plugin:0.3.0'

JMH Version:

jmh {
  jmhVersion = '1.12'
}

@artyushov
Copy link
Owner

@pranasblk Are you sure you have jmh-generator-annprocess on your classpath?
Have you tried rebuilding the project?

@pranasblk
Copy link

pranasblk commented Apr 20, 2016

Yes, the explicit entry to the classpath of jmh scope was missing (dynamically resolved in gradle run-time and IntelliJ previously). Thanks for the note!

@jaredjstewart
Copy link

@pranasblk What specifically did you need to do in order to add jmh-generator-annprocess to the classpath of jmh scope? I tried adding jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.12' to my build.gradle to no avail.

@pranasblk
Copy link

@jaredjstewart I use local/proxied corresponding artefacts. JMH related fragments I use:

buildscript {
  repositories {
    maven /* ... internalRepo ... /*
  }
  dependencies {
    classpath 'me.champeau.gradle:jmh-gradle-plugin:0.3.0',
                    'net.ltgt.gradle:gradle-apt-plugin:0.6'
  }
}
apply plugin: 'me.champeau.gradle.jmh'
apply plugin: 'net.ltgt.apt'

// ...
jmh {
  jmhVersion = '1.12'
}
// ...

dependencies {
// ...
  jmh group: 'commons-io' , name: 'commons-io', version: '2.4'
  jmh group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.12'
// ...
}

//..
eclipse {
  classpath {
//..    
     plusConfigurations += [configurations.jmh]
  }
}

@davidmichaelkarr
Copy link

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?

@davidmichaelkarr
Copy link

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.

@stepan-romankov
Copy link

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

@danieldietrich
Copy link

Ran into the same problem. If you are on Gradle, like me, then https://github.com/melix/jmh-gradle-plugin does really simplify it!

@wordlessly
Copy link

wordlessly commented Apr 30, 2019

Just tried to replicate this example: https://www.mkyong.com/java/java-jmh-benchmark-tutorial

I am not using Maven but Eclipse:

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:98) at org.openjdk.jmh.runner.BenchmarkList.find(BenchmarkList.java:122) at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:263) at org.openjdk.jmh.runner.Runner.run(Runner.java:209) at com.mkyong.benchmark.BenchmarkLoop.main(BenchmarkLoop.java:35)

/usr/lib/jvm/java-8-openjdk-amd64/bin/java -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:42615 -javaagent:/home/nemo/Desktop/eclipse/configuration/org.eclipse.osgi/567/0/.cp/lib/javaagent-shaded.jar -Dfile.encoding=UTF-8 -classpath /home/nemo/Desktop/JMH-Concurrency/bin:/home/nemo/.gradle/caches/modules-2/files-2.1/org.openjdk.jmh/jmh-generator-annprocess/1.21/7aac374614a8a76cad16b91f1a4419d31a7dcda3/jmh-generator-annprocess-1.21.jar:/home/nemo/.gradle/caches/modules-2/files-2.1/org.openjdk.jmh/jmh-core/1.21/442447101f63074c61063858033fbfde8a076873/jmh-core-1.21.jar:/home/nemo/.gradle/caches/modules-2/files-2.1/net.sf.jopt-simple/jopt-simple/4.6/306816fb57cf94f108a43c95731b08934dcae15c/jopt-simple-4.6.jar:/home/nemo/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-math3/3.2/ec2544ab27e110d2d431bdad7d538ed509b21e62/commons-math3-3.2.jar com.mkyong.benchmark.BenchmarkLoop

@dmytro-y-dev
Copy link

dmytro-y-dev commented Sep 6, 2020

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.

@bwaldvogel
Copy link

@metamaker: Switching from testRuntimeOnly to testAnnotationProcessor made things actually worse for me (running the benchmark from IntelliJ)

@stokito stokito changed the title Unable to find the resource: /META-INF/BenchmarkList Scala: Unable to find the resource: /META-INF/BenchmarkList Oct 14, 2020
@shashank070
Copy link

testAnnotationProcessor

This works for me , I am also using JMH + JUnit

@ghost
Copy link

ghost commented Nov 16, 2020

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

dfa1 added a commit to dfa1/graphql-java that referenced this issue Dec 2, 2020
aleksandarsusnjar pushed a commit to aleksandarsusnjar/graphql-java that referenced this issue May 14, 2021
@NicholasMoser
Copy link

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.

@caseyscarborough
Copy link

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

@andreilam
Copy link

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'

@GavinRay97
Copy link

GavinRay97 commented Sep 5, 2022

@caseyscarborough Thanks, you're a life-saver!

@ZachMurray
Copy link

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

Had to add this and that build plugin to POM.XML

  <dependencies>
    <dependency>
      <groupId>org.openjdk.jmh</groupId>
      <artifactId>jmh-core</artifactId>
      <version>${jmh.version}</version>
    </dependency>
    <dependency>
      <groupId>org.openjdk.jmh</groupId>
      <artifactId>jmh-generator-annprocess</artifactId>
      <version>${jmh.version}</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <finalName>benchmarks</finalName>
              <transformers>
                <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>org.openjdk.jmh.Main</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

@nagkumar
Copy link

nagkumar commented Jun 2, 2023

testAnnotationProcessor

This worked for me...
testAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:1.36")

@WebTiger89
Copy link

WebTiger89 commented Oct 9, 2023

Unfortunately, none of these suggestions work:

ERROR: Unable to find the resource: /META-INF/BenchmarkList

. Using kotlin + gradle + jmh-gradle-plugin. The gradle plugin generates some tasks, e.g. jmhCompileGeneratedClasses. Running this task logs following:

Writing out Java source to C:\Users\Peter\IdeaProjects\TestJmh\build\jmh-generated-sources and resources to C:\Users\Peter\IdeaProjects\TestJmh\build\jmh-generated-resources

No file is generated in build/classes/kotlin/jmh/META-INF/
image

Even the oldest uploaded plugin version (0.6.0) does generate it this way.

When I copy the files BenchmarkList + CompilerHints manually into build/classes/kotlin/jmh/META-INF/ , I can run the benchmak via IDE but get following error for every iteration:

java.lang.IllegalArgumentException: Benchmark does not match a class
at org.openjdk.jmh.util.ClassUtils.loadClass(ClassUtils.java:90)
at org.openjdk.jmh.runner.BenchmarkHandler.(BenchmarkHandler.java:68)
at org.openjdk.jmh.runner.BaseRunner.runBenchmark(BaseRunner.java:232)
at org.openjdk.jmh.runner.BaseRunner.doSingle(BaseRunner.java:138)
at org.openjdk.jmh.runner.BaseRunner.runBenchmarksForked(BaseRunner.java:75)
at org.openjdk.jmh.runner.ForkedRunner.run(ForkedRunner.java:72)
at org.openjdk.jmh.runner.ForkedMain.main(ForkedMain.java:84)
Caused by: java.lang.ClassNotFoundException: org.example.jmh_generated.Test_sqrtBenchmark_jmhTest

@stokito stokito pinned this issue Dec 6, 2023
@frevib
Copy link

frevib commented Aug 13, 2024

@WebTiger89 Using kapt it works for Kotlin. Add these two lines in build.gradle.kts:

https://github.com/frevib/coroutine-jmh-benchmarks-virtual-threads/blob/main/build.gradle.kts#L4

https://github.com/frevib/coroutine-jmh-benchmarks-virtual-threads/blob/main/build.gradle.kts#L22

Now you can press the "play" button in Intellij to run the JMH benchmarks.

I wasn't able to make it work using kapts replacement, ksp.

@cbsingh1
Copy link

cbsingh1 commented Nov 6, 2024

Adding below line in my build.gradle solves it for me.

jmhAnnotationProcessor ("org.openjdk.jmh:jmh-generator-annprocess:1.36")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests