5

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?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
user1226868
  • 1,708
  • 5
  • 18
  • 29

2 Answers2

6

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

Juan Saravia
  • 7,661
  • 6
  • 29
  • 41
  • 1
    As I understand, yes. In the gradle issue one person excludes a yahoo and google libraries. – Juan Saravia Sep 30 '14 at 14:55
  • Won't this exclude classes that START with the word Dao? The question was for classes that END with Dao. Should the filter be '**/*Dao.class' ? – mikhail Mar 11 '15 at 13:44
  • that's true what you said but there is no Dao.class file to exclude, the classes are like DaoProfile.class, DaoManager.class, etc. So that's why I'm using Dao*.class. – Juan Saravia Mar 12 '15 at 14:29
2

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
            }
        }
    }
}
Celt
  • 2,469
  • 2
  • 26
  • 43