2
votes

I want to exclude some clasess from JaCoCo but the exclude doest seem to work.

For example i want to exclude all Java clasess that end with Dao (for example com.company.EmplyeeDao).

I have tried the following code, but it still shows up when i push this to sonar / use JacocoTestReport.

test {
    jacoco {
        append = true
        destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
        classDumpFile = file("$buildDir/jacoco/classpathdumps")
        excludes = ['*Dao']
}
}

I'm using this in combination with Android. What is going on?

2
Perhaps try some variations such as *Dao.class or **/*Dao.class.Peter Niederwieser
also see this gradle solution: stackoverflow.com/a/43196918/907576radistao

2 Answers

4
votes

Try something like this:

excludes: ['**/Dao*.class']

But as I understand, this will exclude the class from jacoco but the Report that Jacoco creates will show you "0% of coverage": Gradle issue: https://issues.gradle.org/browse/GRADLE-2955

1
votes

For newer version of gradle (6+) use this:

jacocoTestCoverageVerification {
    violationRules {
        rule {
            includes = ['com/myapp/*']
            excludes = [
                    'com/myapp/folderToExclude1/*',
                    'com/myapp/folderToExclude2/*',
            ]
           limit {
                minimum = 0.85
            }
        }
    }
}