Last active
February 26, 2018 13:18
-
-
Save mcassiano/eb2a3f97d759ad03926e4e08d86ff0a0 to your computer and use it in GitHub Desktop.
Jacoco aggregated test coverage report (multiple 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.0' | |
} | |
def exclude = [ | |
// list of classes you want to exclude from test coverage | |
] | |
task jacocoReport(type: JacocoReport) { | |
group "Reporting" | |
description "Generate Jacoco coverage reports." | |
reports { | |
xml.enabled = false | |
html.enabled = false | |
} | |
// if you use kotlin, add its source set here too! | |
sourceDirectories = files(["$project.projectDir/src/main/java"]) | |
classDirectories = (file("$project.buildDir/intermediates/classes/debug").exists() | |
? fileTree(dir: "$project.buildDir/intermediates/classes/debug", excludes: exclude) | |
: fileTree(dir: "$project.buildDir/classes", excludes: exclude)) | |
// scans for both unit and instrumented test coverage results | |
executionData = fileTree(dir: "$project.buildDir", includes: ["jacoco/*.exec", "outputs/code-coverage/connected/*.ec"]) | |
} |
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.0' | |
} | |
buildscript { | |
// ... | |
} | |
allprojects { | |
repositories { | |
google() | |
jcenter() | |
maven { url "https://jitpack.io" } | |
} | |
} | |
// ... | |
subprojects { | |
// for sub modules, configure their test reports | |
apply from: rootProject.file("gradle/quality.gradle") | |
} | |
// ... | |
// root report | |
task jacocoRootReport(type: JacocoReport) { | |
group "Reporting" | |
description "Generate Jacoco coverage reports." | |
reports { | |
xml.enabled = false | |
html.enabled = true | |
} | |
// collecting all source sets, compiled classes and coverage binaries from sub projects | |
def sourceSets = subprojects.collect { project -> project.jacocoReport.sourceDirectories }.flatten() | |
def classDirs = subprojects.collect { project -> project.jacocoReport.classDirectories }.flatten() | |
def coverageBinaries = subprojects.collect { project -> project.jacocoReport.executionData }.flatten() | |
sourceDirectories = files(sourceSets) | |
classDirectories = files(classDirs) | |
executionData = files(coverageBinaries) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You also need to:
For the last requirement you can also depend on those tasks, but for me it does not work because I don't run instrumented tests on my CI server (Firebase Test Lab to the rescue)