gradlejacocosonarcloud

JaCoCo exclusions are being ignored by Sonar


I use the Gradle JaCoCo plugin, according to the exclusion list some folders must be excluded from the test coverage check. But when I run gradle sonar all these folders are being processed by Sonarcloud.

How can I force SonarCloud to ignore these folders?

enter image description here

jacocoTestReport {
dependsOn test
reports {
    xml.required = true
    html.required = true
}
afterEvaluate {
    classDirectories.setFrom(files(classDirectories.files.collect {
        fileTree(dir: it, exclude: [
                'by/litvin/localsandbox/model/*',
                'by/litvin/localsandbox/mapper/*',
                'by/litvin/localsandbox/data/*',
                'by/litvin/localsandbox/data/*',
                'by/litvin/localsandbox/messaging/event/*',
                'by/litvin/localsandbox/messaging/serializer/*',
                'by/litvin/localsandbox/config/*',
                'by/litvin/localsandbox/LocalSandboxApplication.*'
        ])
    }))
}

}


Solution

  • I found a solution, JaCoCo exclusion list is not enough, you need to exclude these packages in the sonar plugin config as well:

    sonarqube {
        properties {
            def projectPath = "**/*by/litvin/localsandbox"
            def exclusionList = [
                    "${projectPath}/model/*",
                    "${projectPath}/config/*",
                    "${projectPath}/data/*",
                    "${projectPath}/messaging/serializer/*",
                    "${projectPath}/messaging/event",
                    "${projectPath}/LocalSandboxApplication.*"
            ].join(', ')
            property "sonar.coverage.exclusions", exclusionList
        }
    }