Created
September 1, 2019 10:29
-
-
Save felipefpx/392b6eb602999c5d244c89aa89468356 to your computer and use it in GitHub Desktop.
Jacoco Merged Report for Multimodule Android with Kotlin DSL
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
#!/bin/bash | |
clear | |
./gradlew clean mergedJacocoReport | |
./gradlew jacocoFullReport | |
REPORT_PATH="file://$(pwd)/build/reports/jacoco/jacocoFullReport/html/index.html" | |
echo ${REPORT_PATH} | pbcopy | |
echo "Report available at:" | |
echo ${REPORT_PATH} | |
echo "Report file path copied to clipboard. You can paste it in your favorite browser. :)" | |
# | |
# Before use it, in the first time, you must guarantee some running permissions: | |
# chmod +x coverage.sh | |
# | |
# After that, you just need to run: | |
# ./coverage.sh | |
# | |
# It will generate coverage report and copy the html report path to your clipboard. |
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
// Put it at root/buildSrc/src/main/kotlin | |
@file:Suppress("UnstableApiUsage") | |
plugins { | |
jacoco | |
} | |
tasks.withType<Test> { | |
configure<JacocoTaskExtension> { | |
isIncludeNoLocationClasses = true | |
} | |
} | |
task<JacocoReport>("mergedJacocoReport") { | |
dependsOn("testDebugUnitTest", "createDebugCoverageReport") | |
reports { | |
xml.isEnabled = false | |
html.isEnabled = false | |
} | |
val fileFilter = mutableSetOf( | |
"**/R.class", | |
"**/R\$*.class", | |
"**/BuildConfig.*", | |
"**/Manifest*.*", | |
"**/*Test*.*", | |
"android/**/*.*", | |
"**/*\$Lambda$*.*", // Jacoco can not handle several "$" in class name. | |
"**/*\$inlined$*.*" // Kotlin specific, Jacoco can not handle several "$" in class name. | |
) | |
classDirectories.setFrom( | |
fileTree(project.buildDir) { | |
include( | |
"**/classes/**/main/**", | |
"**/intermediates/classes/debug/**", | |
"**/intermediates/javac/debug/*/classes/**", // Android Gradle Plugin 3.2.x support. | |
"**/tmp/kotlin-classes/debug/**" | |
) | |
exclude(fileFilter) | |
} | |
) | |
sourceDirectories.setFrom( | |
fileTree("${project.buildDir}") { | |
include( | |
"src/main/java/**", | |
"src/main/kotlin/**", | |
"src/debug/java/**", | |
"src/debug/kotlin/**" | |
) | |
} | |
) | |
executionData.setFrom( | |
fileTree(project.buildDir) { | |
include( | |
"outputs/code_coverage/**/*.ec", | |
"jacoco/jacocoTestReportDebug.exec", | |
"jacoco/testDebugUnitTest.exec", | |
"jacoco/test.exec" | |
) | |
} | |
) | |
} |
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
// root/build.gradle.kts | |
buildScript { | |
// [...] | |
dependencies { | |
// [...] | |
classpath("com.palantir:jacoco-coverage:0.4.0") | |
} | |
} | |
// [...] | |
plugins { | |
id("com.palantir.jacoco-full-report") version "0.4.0" | |
} | |
// optional: | |
jacocoFull { | |
excludeProject(":excluded_module1", ":excluded_module2") | |
} | |
// [...] |
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
// submodule/build.gradle.kts | |
plugins { | |
// [...] | |
id(mergedJacocoReport) | |
} | |
jacoco { | |
toolVersion = "0.8.2" | |
} | |
android { | |
defaultConfig { | |
// [...] | |
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | |
} | |
testOptions { | |
execution = "ANDROIDX_TEST_ORCHESTRATOR" | |
animationsDisabled = true | |
unitTests.apply { | |
isReturnDefaultValues = true | |
isIncludeAndroidResources = true | |
} | |
} | |
} | |
// [...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you also use SonarQube to view the coverage reports?