How do I use OpenJDK JMH with Gradle?

I’m trying to integrate JMH into a Java project that uses Gradle. JMH is an OpenJDK project that lets you run micro benchmarks on your Java code.

The tool works by first running an annotation processor from ‘jmh-core’ to generate synthetic code with the benchmarking instrumentation and a list of those benchmark files. You then package the generated code and all dependencies with the benchmark list in ‘META-INF/*’ and run the JAR.

I’d like to do this with a sourceSet called ‘perfTest’ in my current project. I’m not sure how to do this with Gradle, there’s a Maven plugin and an Ant build script.

I think it involves creating a separate ‘sourceSet’ and a ‘JavaCompile’ task and a ‘JavaExec’ task to run the sequence of events required by JMH but I’m not sure how.

Cheers,

Chris

Here’s a way to do it: http://stackoverflow.com/questions/20443997/how-to-use-jmh-with-gradle

Hey Luke,

Thanks for the response. :slight_smile:

I’ve seen this answer on StackOverflow. It depends on the Shadow plugin, what I’m looking for is a way to use the ‘JavaCompile’ and ‘JavaExec’ tasks as part of a separate ‘sourceSet’ so that I can run ‘gradle benchmark’ as a task alongside the usual build tasks for the project.

Cheers,

Chris