Created
March 2, 2019 13:15
-
-
Save tristanlins/9ac55dc7e6692b8c98dc0242724b12af to your computer and use it in GitHub Desktop.
Gradle Jacoco Plugin and Gitlab Coverage
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
plugins { | |
id 'jacoco' | |
} | |
jacocoTestReport { | |
reports { | |
xml.enabled true | |
} | |
} | |
task coverageReport() { | |
dependsOn jacocoTestReport | |
def reportFile = project.file("build/reports/jacoco/test/jacocoTestReport.xml") | |
inputs.file(reportFile) | |
doLast { | |
def slurper = new XmlSlurper() | |
slurper.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false) | |
slurper.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) | |
def xml = slurper.parse(reportFile) | |
def counter = xml.counter.find { | |
node -> node.@type == 'BRANCH' | |
} | |
def missed = [email protected]() | |
def covered = [email protected]() | |
def total = missed + covered | |
def percentage = covered / total * 100 | |
printf "Missed %.0f branches%n", missed | |
printf "Covered %.0f branches%n", covered | |
printf "Total %.0f%%%n", percentage | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It helped me! Thanks!