SonarQube: Coverage incomplete on multimodule gradle project with JaCoCo

后端 未结 2 1057
忘掉有多难
忘掉有多难 2020-12-10 15:00

I am building a SonarQube 6.2 server which is already analyzing my Java 8/Gradle 3.3 projects. When adding JaCoCo to a multimodule gradle project, I realized that SonarQube

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 16:00

    If you are interested in the solution with sonar.jacoco.reportPaths (see answer of Godin), have looke at this gradle code:

    tasks.getByName('sonarqube') {
        doFirst {
            // lazy initialize the property to collect all coverage files
            def jacocoFilesFromSubprojects = subprojects.findAll {it.plugins.hasPlugin('jacoco')}
                    .collect {it.tasks.withType(Test)}.flatten().collect {it.jacoco.destinationFile}
    
            sonarqube.properties {
                property "sonar.jacoco.reportPaths", jacocoFilesFromSubprojects.join(',')
            }
        }
    }
    

    This will collect all coverage binary files and set them as comma-separated list to the sonar property. Considers all test tasks of sub projects where jacoco is applied and their jacoco destination file configured.

提交回复
热议问题