I'm using Jacoco 0.8.5 and Gradle 6.4, I have an Android project which I'm trying to setup my code coverage. Here is how my jacoco.gradle file:
apply plugin: 'jacoco'
def flavor = "debug"
def unitTestTask = "testDebugUnitTest"
jacoco {
toolVersion = "0.8.5"
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
final androidExcludes =
["**/R.class",
"**/R\$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*Test*.*",
"android/**/*.*",
"**/*_MembersInjector.class",
"**/Dagger*Component.class",
"**/Dagger*Component\$Builder.class",
"**/*Module_*Factory.class",
"**/*_Provide*Factory*.*",
"**/*_Factory*.*",
"**/*Activity*.*",
"**/*Fragment*.*",
"**/*ViewHolder*.*",
"**/*Adapter*.*"]
task jacocoReport(type: JacocoReport, dependsOn: "${unitTestTask}") {
reports {
xml.enabled = true
html.enabled = true
}
afterEvaluate {
def debugTree = fileTree(dir: "$project.buildDir/intermediates/javac/${flavor}/classes",
excludes: androidExcludes)
def kotlinDebugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/${flavor}/",
excludes: androidExcludes)
def mainSrc = "$project.projectDir/src/main/java"
sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([debugTree], [kotlinDebugTree]))
executionData.setFrom(fileTree(dir: project.buildDir, includes: ["jacoco/${unitTestTask}.exec"]))
}
}
I want to remove from the coverage some files, set in androidExcludes, for example Activities or Adapter. But currently the report doesn't take into account my excludes, as you can see in the following report from CodeCov I still have excluded files (ViewHolder or Adapter)

