Skip to content

Instantly share code, notes, and snippets.

@Aidan128
Last active March 6, 2022 18:09
Show Gist options
  • Save Aidan128/d15db6cadd10505bb94dd362e75f4a8e to your computer and use it in GitHub Desktop.
Save Aidan128/d15db6cadd10505bb94dd362e75f4a8e to your computer and use it in GitHub Desktop.
jacoco gradle script for inclusion in module-level build.gradle
apply plugin: 'jacoco'
jacoco {
toolVersion '0.8.7'
}
task jacocoUnifiedReport(type: JacocoReport) {
reports {
xml.enabled = true
html.enabled = true
}
def sourceDirectories = subprojects.collect { subproject ->
"${subproject.projectDir}/src/main/java"
}
def classDirectories = subprojects.collect { subproject ->
["${subproject.buildDir}/intermediates/javac/debug", "${subproject.buildDir}/tmp/kotlin-classes/debug"]
}.flatten()
def classFiles = classDirectories.collect { directory ->
def excludesFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
fileTree(dir: file(directory), excludes: excludesFilter)
}
def executionDirectories = subprojects.collect { subproject ->
["${subproject.buildDir}/outputs/code_coverage", "${subproject.buildDir}/jacoco"]
}.flatten()
def executionFiles = executionDirectories.collect { directory ->
def includesFilter = ['*.ec', '*.exec']
fileTree(dir: file(directory), includes: includesFilter)
}
getSourceDirectories().setFrom(sourceDirectories)
getClassDirectories().setFrom(classFiles)
getExecutionData().setFrom(executionFiles)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment