Hi I\'m hitting the following exception when running a JaCoCo coverage:
org
There are two ways to avoid this:
1)Rename one of the duplicates: I've seen this problem quite often when it comes to maven projects. Even if those two classes are in two different modules, having same names for two different classes is not really a good idea.
2)Exclude one of them: Refer this SO thread for more information.
I hit the same issue as you. It turns out I had two jars in my project folder that did the same thing, even though only one of them was in the build path. Check if you have more than one hamcrest jar in your code.
I agree with rb512. One more case/area where this error can come is, during compilation process if we are using JIBX/WST etc or similar other steps/process which creates dynamic class files (at compile time) i.e. for which we don't have any valid corresponding source file (.java/.groovy etc) in the workspace.
In that's case, your workspace will have extra class file(s) and when jacoco will try to generate the report, it'll error out with the same error for a duplicate class. If you find this error due to this case, you have to remove any class files before running jacoco reports
If you are using Gradle (for Maven, do the same in Maven pom .xml file), see the doFirst
block below which is doing the trick.
jacocoTestReport {
//cleaning up the JiBx classes to jacoco will not cause problems for CareDiscovery
doFirst {
delete fileTree (dir: "${buildDir}/classes", include: "**/JiBX_*.class")
}
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
executionData = fileTree(dir: 'build/jacoco', include: '**/*.exec')
reports {
xml{
enabled true
//Following value is a file
destination "${buildDir}/reports/jacoco/xml/jacoco.xml"
}
csv.enabled false
html {
enabled true
//Following value is a folder
destination "${buildDir}/reports/jacoco/html"
}
}
sourceDirectories = files(['src/java','src/main/java', 'src/main/groovy'])
classDirectories = files('build/classes/main')
}