How to use JMH when not using Maven

Aleksey Shipilev aleksey.shipilev at oracle.com
Mon Aug 5 13:22:09 PDT 2013


On 08/05/2013 11:27 PM, Aleksey Shipilev wrote:
> On 08/05/2013 11:20 PM, Richard Bair wrote:
>> How do I prepare the benchmarks to be in a form that jmh can then 
>> execute?
> 
> Since we are generating the synthetic code, you generally need to "just"
> compile the benchmarks with the JMH's annotation processor on board, and
> then pack all the classes and resources into the JAR with the JMH
> Main-Class.

This thing works for me:

----------- 8< --------------------------------------------------------

apply plugin: 'java'
apply plugin: 'shadow'

buildscript {
    repositories {
        mavenCentral()
        maven {
            name 'Shadow'
            url 'http://dl.bintray.com/content/johnrengelman/gradle-plugins'
        }
    }
    dependencies {
        classpath 'org.gradle.plugins:shadow:0.7.4'
    }
}

jar {
    manifest {
        attributes 'Main-Class': 'org.openjdk.jmh.Main'
    }
}

repositories {
    mavenLocal()
    mavenCentral()
}

build.doLast {
    tasks.shadow.execute()
}

shadow {
    outputFile = new File("build/libs/microbenchmarks.jar")
}

dependencies {
    compile group: 'org.openjdk.jmh', name: 'jmh-core', version:
'1.0-SNAPSHOT'
}

----------- 8< --------------------------------------------------------

Thanks,
Aleksey.


More information about the jmh-dev mailing list