Created
July 9, 2021 16:34
-
-
Save NinoDLC/5225fd3334f2464de3965f1c32fb1638 to your computer and use it in GitHub Desktop.
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
// open JaCoCo report after generation | |
def openReport(htmlOutDir) { | |
final reportPath = "$htmlOutDir\\index.html" | |
println "HTML Report: $reportPath" | |
def os = org.gradle.internal.os.OperatingSystem.current() | |
if (os.isWindows()) { | |
exec { commandLine 'cmd', '/c', "start $reportPath" } | |
} else if (os.isMacOsX()) { | |
exec { commandLine 'open', "$reportPath" } | |
} else if (os.isLinux()) { | |
try { | |
exec { commandLine 'xdg-open', "$reportPath" } | |
} catch (Exception ignored) { | |
if (localProperties.containsKey("linux-html-cmd")) { | |
exec { commandLine properties.get("linux-html-cmd"), "$reportPath" } | |
} else { | |
println "'linux-html-cmd' property could not be found in 'local.properties'" | |
} | |
} | |
} | |
} | |
// JaCoCo stuff | |
android.applicationVariants.all { variant -> | |
def variantName = variant.name.capitalize() | |
def filesToAnalyze = [ | |
'**/*ViewModel.class', | |
'**/*Repository.class' | |
] | |
task("jacoco${variantName}Report", type: JacocoReport, dependsOn: "test${variantName}UnitTest") { | |
group 'Reporting' | |
description "Generate ${variantName} Jacoco coverage reports." | |
def htmlOutDir = layout.buildDirectory.dir("reports/jacoco/$name/html").get().asFile | |
doLast { | |
openReport htmlOutDir | |
} | |
reports { | |
xml.enabled = true | |
html { | |
destination htmlOutDir | |
} | |
} | |
getSourceDirectories().setFrom(files(android.sourceSets.main.java.srcDirs)) | |
getExecutionData().setFrom(files("${buildDir}/jacoco/test${variantName}UnitTest.exec")) | |
getClassDirectories().setFrom(fileTree(dir: variant.javaCompiler.destinationDir, includes: filesToAnalyze)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment