1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| apply plugin: 'jacoco'
tasks.withType(Test) { jacoco { includeNoLocationClasses = true excludes = ['jdk.internal.*'] } }
android { testCoverage { jacocoVersion "0.8.10" } buildTypes { debug { testCoverageEnabled true } } }
def sourceName = 'devDebug' def testTaskName = "test${sourceName.capitalize()}UnitTest"
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDevDebugUnitTest']) { group = "JacocoReport" description = "Generate Jacoco coverage reports on the ${sourceName.capitalize()} build."
reports { xml.getRequired().set(true) csv.getRequired().set(false) html.getRequired().set(true) html.outputLocation.set(file("${buildDir}/reports/coverage")) xml.outputLocation.set(file("${buildDir}/reports/jacoco.xml")) }
def fileFilter = [ '**/*JsonAdapter.*', '**/dao/**', '**/*GeneratedInjector.*', '**/*EntryPoint.*', '**/databinding/**/*.class', '**/databinding/*Binding.class', '**/databinding/*', '**/bumptech/*', '**/BR.*', '**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*', '**/*MapperImpl*.*', '**/*$ViewInjector*.*', '**/*$ViewBinder*.*', '**/BuildConfig.*', '**/*Component*.*', '**/*BR*.*', '**/Manifest*.*', '**/*$Lambda$*.*', '**/*Companion*.*', '**/*Module*.*', '**/*Dagger*.*', '**/*Hilt*.*', '**/*MembersInjector*.*', '**/*_MembersInjector.class', '**/*_Factory*.*', '**/*_Provide*Factory*.*', '**/*Extensions*.*', '**/*$Result.*', '**/*$Result$*.*' ]
def javaClasses = [] def kotlinClasses = [] def javaSrc = []
rootProject.subprojects.each { proj -> if (proj.name != 'app') { javaClasses << fileTree(dir: "$proj.buildDir/intermediates/javac/$sourceName/classes", excludes: fileFilter) kotlinClasses << fileTree(dir: "$proj.buildDir/tmp/kotlin-classes/$sourceName", excludes: fileFilter) javaSrc << "$proj.projectDir/src/main/java" } }
sourceDirectories.from = files([javaSrc]) classDirectories.from = files([javaClasses, kotlinClasses]) def executionDir = "${project.buildDir}/outputs/unit_test_code_coverage/${sourceName}UnitTest/${testTaskName}.exec" executionData.from = files(executionDir) print("executionData Dir:$executionDir") }
|