Last active
October 20, 2023 09:23
-
-
Save laithnurie/f98a1f256ddbeab962f2c64b5361d1ed to your computer and use it in GitHub Desktop.
One Jacoco task for one single report for multiple gradle sub modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'jacoco' | |
jacoco { | |
toolVersion = "0.8.8" | |
} | |
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) { | |
group "Reporting" | |
description "Generate Jacoco coverage reports." | |
reports { | |
xml.required = true | |
html.required = true | |
html.destination file("${rootProject.buildDir}/coverage-report") | |
xml.destination file("${rootProject.buildDir}/coverage-report/whole_report_coverage.xml") | |
} | |
def javaClasses = [] | |
def kotlinClasses = [] | |
def javaSrc = [] | |
def kotlinSrc = [] | |
def execution = [] | |
def fileFilter = [ | |
// data binding | |
'**/databinding/*', | |
'android/databinding/**/*.class', | |
'**/android/databinding/*Binding.class', | |
'**/android/databinding/*', | |
'**/androidx/databinding/*', | |
'**/BR.*', | |
// android | |
'**/R.class', | |
'**/R$*.class', | |
'**/BuildConfig.*', | |
'**/Manifest*.*', | |
'**/*Test*.*', | |
'android/**/*.*', | |
// kotlin | |
'**/*MapperImpl*.*', | |
'**/*$ViewInjector*.*', | |
'**/*$ViewBinder*.*', | |
'**/BuildConfig.*', | |
'**/*Component*.*', | |
'**/*BR*.*', | |
'**/Manifest*.*', | |
'**/*$Lambda$*.*', | |
'**/*Companion*.*', | |
'**/*Module*.*', | |
'**/*Dagger*.*', | |
'**/*Hilt*.*', | |
'**/*MembersInjector*.*', | |
'**/*_MembersInjector.class', | |
'**/*_Factory*.*', | |
'**/*_Provide*Factory*.*', | |
'**/*Extensions*.*', | |
// sealed and data classes | |
'**/*$Result.*', | |
'**/*$Result$*.*', | |
// adapters generated by moshi | |
'**/*JsonAdapter.*', | |
// Hilt | |
'**/*Module.kt', | |
'**/di/**', | |
'dagger.hilt.internal/*', | |
'hilt_aggregated_deps/*', | |
'**/*$Result.*', /* filtering `sealed` and `data` classes */ | |
'**/*$Result$*.*',/* filtering `sealed` and `data` classes */ | |
'**/*Args*.*', /* filtering Navigation Component generated classes */ | |
'**/*Directions*.*', /* filtering Navigation Component generated classes */ | |
'**/*inlined*.class', /* filtering inlined classes */ | |
'**/composables/**', | |
'**/*Preview*.*' | |
] | |
def exclude_coverage_modules = ['core-test'] | |
rootProject.subprojects.each { proj -> | |
if(exclude_coverage_modules.contains(proj.name)) { | |
return | |
} | |
// 'debug' is variant, you can add multiple in new lines depending on where you tests run against | |
javaClasses << fileTree(dir: "$proj.buildDir/intermediates/javac/debug", excludes: fileFilter) | |
kotlinClasses << fileTree(dir: "$proj.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter) | |
javaSrc << "$proj.projectDir/src/main/java" | |
kotlinSrc << "$proj.projectDir/src/main/kotlin" | |
execution << fileTree(dir: proj.buildDir, | |
includes: [ | |
'outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec', | |
'outputs/code_coverage/debugAndroidTest/connected/**/*.ec']) | |
} | |
getSourceDirectories().setFrom(javaSrc, kotlinSrc) | |
getClassDirectories().setFrom(javaClasses, kotlinClasses) | |
getExecutionData().setFrom(execution) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment