Created
December 21, 2017 16:59
-
-
Save jaredsburrows/319f13f029c6d32251bf12e41f876b83 to your computer and use it in GitHub Desktop.
Jacoco for multi-module projects
This file contains 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") | |
} | |
def include = [""] | |
def exclude = [ | |
// Android | |
"**/R.class", | |
"**/R\$*.class", | |
"**/Manifest*.*", | |
"**/BuildConfig.*", | |
// Android databinding | |
"**/*databinding/*", | |
"**/BR.*", | |
// Dagger | |
"**/*Dagger*.*", | |
"**/Dagger*Component.class", | |
"**/Dagger*Component\$Builder.class", | |
"**/*Module.*", | |
"**/*MembersInjector*.*", | |
"**/*_MembersInjector.class", | |
"**/*_Factory.*", | |
"**/*Module_*Factory.class", | |
"**/*_Provide*Factory*.*"] | |
task("jacocoAllReport", type: JacocoReport) { | |
group = "Reporting" | |
description = "Generate Jacoco coverage report for the entire project." | |
reports { | |
xml.enabled = false | |
html.enabled = true | |
} | |
sourceDirectories = files(rootProject.subprojects.collect { subProject -> subProject.files("./src/main/java") + subProject.files("./src/main/kotlin") }.toArray()) | |
classDirectories = files(rootProject.subprojects.collect { subProject -> (file("$subProject.buildDir/intermediates/classes/debug").exists() | |
? fileTree(dir: "$subProject.buildDir/intermediates/classes/debug", includes: include, excludes: exclude) | |
: fileTree(dir: "$subProject.buildDir/classes", includes: include, excludes: exclude)) }.toArray()) | |
executionData = fileTree(dir: "$rootProject.projectDir", includes: [ | |
"**/*.exec", // unit test - testDebugUnitTest | |
"**/*.ec", // android test - createDebugCoverageReport or spoonDebugAndroidTest | |
]) | |
} |
This file contains 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") | |
plugin("checkstyle") | |
} | |
def include = ["**/com/yammer/**"] | |
def exclude = [ | |
// Android | |
"**/R.class", | |
"**/R\$*.class", | |
"**/Manifest*.*", | |
"**/BuildConfig.*", | |
// Android databinding | |
"**/*databinding/*", | |
"**/BR.*", | |
// Dagger | |
"com/yammer/droid/injection/**/*.class", | |
"**/*Dagger*.*", | |
"**/Dagger*Component.class", | |
"**/Dagger*Component\$Builder.class", | |
"**/*Module.*", | |
"**/*MembersInjector*.*", | |
"**/*_MembersInjector.class", | |
"**/*_Factory.*", | |
"**/*Module_*Factory.class", | |
"**/*_Provide*Factory*.*", | |
// Yammer classes | |
"com/yammer/android/data/model/**/*.class"] | |
/** | |
* Generates Jacoco coverage reports based off the unit tests. | |
*/ | |
task("jacocoReport", type: JacocoReport) { | |
group = "Reporting" | |
description = "Generate Jacoco coverage reports." | |
reports { | |
xml.enabled = false | |
html.enabled = true | |
} | |
sourceDirectories = files(["src/main/java", "src/main/kotlin"]) | |
classDirectories = (file("$project.buildDir/intermediates/classes/debug").exists() | |
? fileTree(dir: "$project.buildDir/intermediates/classes/debug", includes: include, excludes: exclude) | |
: fileTree(dir: "$project.buildDir/classes", includes: include, excludes: exclude)) | |
executionData = fileTree(dir: "$project.buildDir", includes: ["**/*.exec"]) | |
} | |
/** | |
* Generates Checkstyle reports based off the source code. | |
*/ | |
task("checkstyle", type: Checkstyle) { | |
group = "Reporting" | |
description = "Generate Checkstyle reports." | |
reports.html.enabled = true | |
showViolations = true | |
include = ["**/*.java"] | |
// source("") | |
configProperties = [configDir: "${project.rootDir}/config/checkstyle", | |
cacheDir: "${project.buildDir}"] | |
classpath = files() | |
configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment