melix / jmh-gradle-plugin

Integrates the JMH benchmarking framework with Gradle
Apache License 2.0
666 stars 88 forks source link

jmhJar fails due to duplicate classes #125

Open bensku opened 6 years ago

bensku commented 6 years ago

For some reason, running jmh task causes two (probably identical) class files to appear per one Java file:

I'm running JMH task for root project, but plugin and configuration is only applied to one subproject, and appears to be running only for that (as intended). Except, of course, that it does not work - jmhJar cannot deal with two classes with same name, failing the jmh Gradle task.

I have Gradle 4.6, might there some kind of compatibility issue with it? Or are subprojects just not working with this plugin?

denis-zhdanov commented 6 years ago

+1 This makes the plugin unusable. I can offer a sample project which illustrates the problem if necessary.

The strange thing is that sometimes it works somehow

bensku commented 6 years ago

@denis-zhdanov I eventually hacked around the issue. Not a proper fix, but appears to be working well enough for now:

tasks.getByName('jmhJar').doFirst() {duplicatesStrategy(DuplicatesStrategy.EXCLUDE)}

jmh {
    duplicateClassesStrategy = 'exclude'
}
git-ness commented 6 years ago

Ran into this as well and couldn't get past it. I ended up going with https://github.com/Valloric/jmh-playground which seems to be a much better solution imo.

denis-zhdanov commented 6 years ago

@bensku I also 'solved' the problem by finding a combination of gradle and jmh plugin versions which work (with additional setup) - a sample

tbroyer commented 6 years ago

This is (probably) because you have the jmh-generator-annprocess dependency in the classpath: the annotation processor therein will generate the benchmarks, then the JMH plugin's own tasks (jmhRunBytecodeGenerator and jmhCompileGeneratedClasses) will generate them again, leading to the duplicates.