jmh-gradle-plugin icon indicating copy to clipboard operation
jmh-gradle-plugin copied to clipboard

jmhJar fails due to duplicate classes

Open bensku opened this issue 6 years ago • 5 comments

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

  • subproject/build/classes/java/jmh/my/package/jmh/subproject/generated/classname.class
  • subproject/build/jmh-generated-classes/my/package/jmh/subproject/generated/classname.class

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?

bensku avatar Mar 01 '18 19:03 bensku

+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

denis-zhdanov avatar Apr 03 '18 09:04 denis-zhdanov

@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'
}

bensku avatar Apr 03 '18 11:04 bensku

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.

git-ness avatar Apr 09 '18 05:04 git-ness

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

denis-zhdanov avatar Apr 09 '18 06:04 denis-zhdanov

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.

tbroyer avatar Apr 22 '18 11:04 tbroyer