Last active
March 21, 2021 21:29
-
-
Save marchpig/b75fdae13f9c31298285ca1b49e66a63 to your computer and use it in GitHub Desktop.
How to display Jacoco summary in Maven console output
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
def reportFile = new File("target/site/jacoco/index.html") | |
if (!reportFile.exists() || !reportFile.canRead()) { | |
println "[JacocoPrinter] Skipped due to missing report file." | |
return | |
} | |
reportFile.withReader('UTF-8') { reader -> | |
def html = getParser().parseText(reader.readLine()) | |
def totalRow = html.body.table.tfoot.tr | |
def instructionMissed = totalRow.td[1] | |
def instructionRatio = totalRow.td[2] | |
def branchMissed = totalRow.td[3] | |
def branchRatio = totalRow.td[4] | |
println "[JacocoPrinter] Instructions ${instructionRatio} (Missed ${instructionMissed})" | |
println "[JacocoPrinter] Branches ${branchRatio} (Missed ${branchMissed})" | |
} | |
XmlSlurper getParser() { | |
parser = new XmlSlurper() | |
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false) | |
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) | |
return parser | |
} |
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
... | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.jacoco</groupId> | |
<artifactId>jacoco-maven-plugin</artifactId> | |
<version>0.8.3</version> | |
<executions> | |
<execution> | |
<goals> | |
<goal>prepare-agent</goal> | |
</goals> | |
</execution> | |
<execution> | |
<id>report</id> | |
<phase>test</phase> | |
<goals> | |
<goal>report</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
<plugin> | |
<groupId>org.codehaus.gmaven</groupId> | |
<artifactId>groovy-maven-plugin</artifactId> | |
<version>2.1.1</version> | |
<executions> | |
<execution> | |
<phase>test</phase> | |
<goals> | |
<goal>execute</goal> | |
</goals> | |
<configuration> | |
<source>JacocoPrinter.groovy</source> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://medium.com/@marchpig/how-to-display-jacoco-summary-in-maven-console-output-9ab39f1b499f