apply plugin: "jacoco" jacoco { toolVersion "0.8.1" reportsDir = file("$buildDir/reports") } tasks.withType(Test) { jacoco.includeNoLocationClasses = true } // run ./gradlew clean createDebugCoverageReport jacocoTestReport task jacocoTestReport(type: JacocoReport) { group = "Reporting" description = "Generate Jacoco coverage reports" reports { xml.enabled = true html.enabled = true } def excludes = [ "**/R.class", "**/R\$*.class", "**/*\$ViewInjector*.*", "**/BuildConfig.*", "**/Manifest*.*", "**/*Test*.*", "android/**/*.*", "**/*Fragment.*", "**/*Activity.*" ] // generated classes classDirectories = fileTree( // Java generated classes on Android project (debug build) dir: "$buildDir/intermediates/classes/debug", excludes: excludes ) + fileTree( // Kotlin generated classes on Android project (debug build) dir: "$buildDir/tmp/kotlin-classes/debug", excludes: excludes ) // sources sourceDirectories = files([ android.sourceSets.main.java.srcDirs, "src/main/kotlin" ]) executionData = fileTree( dir: project.projectDir, includes: ["**/*.exec" , "**/*.ec"] ) }