JaCoCo Can't add different class with same name: org/hamcrest/BaseDescription

后端 未结 3 1720
陌清茗
陌清茗 2021-01-01 09:44

Hi I\'m hitting the following exception when running a JaCoCo coverage:

    
        org         


        
3条回答
  •  执念已碎
    2021-01-01 10:32

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

提交回复
热议问题