1

I have tried both approach shared here and on another discussion board.

Inside jacocoTestReport - suggested in this blog

    afterEvaluate { 
       classDirectories = files(classDirectories.files.collect { 
           fileTree(
             dir: "build/classes/main", exclude: ['*/com.X.Y.P/**']) 
        }) 
    }

and inside sonarqube as suggest in one another question

property "sonar.coverage.exclusions", "*/com.X.Y.P/**"

But none of them is working for me.

Gradle version -    2.13
jacoco toolVersion = "0.7.4.201502262128"
sonarqube-gradle-plugin:1.2
springBootVersion = '1.5.9.RELEASE'
Avhi
  • 806
  • 2
  • 15
  • 29

1 Answers1

1

Try this (basically, replace the "build/classes/main" by it)

jacocoTestReport {
    afterEvaluate {
        classDirectories = files(classDirectories.files.collect {
            fileTree(dir: it, exclude: '**/Q*')
        })
    }
}
ToYonos
  • 16,469
  • 2
  • 54
  • 70
  • I made the changes but still not working. Here is code : jacocoTestReport{ additionalSourceDirs = files(sourceSets.main.allJava.srcDirs) reports { html.enabled true xml.enabled false csv.enabled false html.destination "build/reports/jacoco/html" } afterEvaluate { classDirectories = files(classDirectories.files.collect { fileTree(dir: it, exclude: '**/com.xyz.domain*') }) } executionData = files('build/jacoco/test.exec') } – Avhi Apr 13 '18 at 12:58
  • `*/com.xyz.domain` won't match much, the package separator is /. Try `**/com/xyz/domain/**` – ToYonos Apr 13 '18 at 13:09
  • Thanks ToYonos, I tried with `**/com/xyz/domain/**` and `**/com/xyz/**`, nothing is changing, getting all packages included in report. – Avhi Apr 13 '18 at 13:48
  • That's the only solution I found on SO, which solved my problem with ignoring several classes, which were generated and I didn't want to measure their coverage. Thanks! – Piotr Wittchen Sep 16 '18 at 12:11