sonarqube gradle plugin excluding jacoco integration tests

前端 未结 2 1422
醉酒成梦
醉酒成梦 2021-02-08 22:47

I\'m trying to integrate the sonarqube gradle plugin with the jacoco plugin:

classpath \'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.1\'

apply plugi

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-08 23:27

    It works for me, but only after merging all jacoco reports into one file AND (important) deleting all other reports

            property "sonar.java.coveragePlugin", "jacoco"
            property "sonar.junit.reportsPath", "$projectDir/build/test-results"
            property 'sonar.jacoco.reportPaths', "${rootProject.buildDir}/jacoco/mergeJacoco.exec"
    

    And you need a merge jacoco task

    Task mergeJacoco = tasks.create('mergeJacoco', JacocoMerge, {
      doFirst {
          delete "$buildDir/jacoco/mergeJacoco.exec"
      }
      destinationFile(new File(buildDir, 'jacoco/mergeJacoco.exec'))
      executionData fileTree('./').include('**/*.exec-partial')
      doLast {
          delete fileTree('./').include('**/test.exec-partial')
      }
    })
    
    mergeJacoco.outputs.upToDateWhen { false }
    project.tasks["sonarqube"].dependsOn mergeJacoco
    mergeJacoco.mustRunAfter ":myProject:test"
    

    And setup jacoco to use those "partial" files

    subprojects {
        ....
        jacoco {
            destinationFile file("$buildDir/jacoco/test.exec-partial")
            append = false
            includes = ['com.mypackage.*']
        }
    }
    

    You'll get unit and IT reports mixed in one, but that's the best I could get

提交回复
热议问题