melix / jmh-gradle-plugin

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

Problem running benchmarks from IntelliJ #76

Open PeterReiter opened 8 years ago

PeterReiter commented 8 years ago

Hello,

I'm using the plugin in combination with IntelliJ IDEA 15.0.4 and I try to run the example JMHSample_25_API_GA, which uses the JMH API.

But when I try to execute the main() method I always get the following error:

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

My build.gradle file:

plugins {
    id "me.champeau.gradle.jmh" version "0.3.0"
}

apply plugin: 'java'
apply plugin: 'idea'

group 'jmhTest'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

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

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

Running the task jmhJar, creates all the needed classes and also the BenchmarkList, in the directory jmh-generated-classes/META-INF

Maybe someone can help me with my problem, best regards Peter

vyazelenko commented 8 years ago

@PeterReiter running benchmarks directly from the IDE is not supported (in other words you use IDE only to write benchmarks). You first need to generate a jar with benchmarks (which you can do by running jmhJar) task and then you would be able to execute benchmarks by:

The advantage of the second approach is that you can specify any command line args for JMH without changing build.gradle file.

So if you would like to run just a JMHSample_25_API_GA via its main method (not as a benchmark). Then you can do the following:

./gradlew jmhJar
java -cp build/libs/xxx-jmh.jar org.openjdk.jmh.samples.JMHSample_25_API_GA
sirati commented 4 months ago

there is a solution explained here: https://stackoverflow.com/a/71286156

for using jmh to also work with the intellij plugin https://github.com/artyushov/idea-jmh-plugin you also have to add

dependencies {
    jmh 'org.openjdk.jmh:jmh-core:+'
    jmh 'org.openjdk.jmh:jmh-generator-annprocess:+'

    jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:+'
}

to your build script. i am not sure why, but i think this fix could easily be employed by the gradle plugin to also just perform these operation