Gradle plugin to parse jacoco report as a markdown.
$ ./gradlew build
> Task :example:jacocoTestReportMarkdown
|Type | Missed/Total| Coverage|
|:--- | ---:| ---:|
|INSTRUCTION|~~8/18~~ 8/24| ~~55.56~~ 66.67%|
|BRANCH | ~~0/2~~ 0/4|(Not Changed)100.00%|
|LINE | ~~2/6~~ 2/8| ~~66.67~~ 75.00%|
Class list with less coverage (Worst 5)
|Class |Instructions(C0)|Branches(C1)|
|:--- | ---:| ---:|
|jp.gr.java_conf.spica.plugin.gradle.jacoco.example.App| 8/29(72.41%)|0/4(100.00%)|
The markdown is output by a file, so you can put the coverage on a Pull Request by using some CI tools. For GitHub actions, you can use github-script to read the markdown and put it to the PR.
Gradle versions:
- 8.x
- 7.x
- 6.1 or later
Java versions:
- 8 or later
This plugin depends on the jacoco plugin. So apply both the jacoco plugin and this plugin.
plugins {
id 'java'
id 'jacoco'
id "com.github.sakata1222.jacoco-markdown" version "X.Y.Z"
}
See also Gradle plugin portal to check the latest version.
First, configure the jacoco plugin based on the jacoco plugin guide.
A task to output coverage report as a markdown will be created by default, and dependencies are also configured automatically.
Configuration of the default task:
- Name is
<name-of-default-jacoco-report>Markdown
(i.e. jacocoTestReportMarkdown) - The task depends on a default JacocoReport task
- A default JacocoReport task finalizedBy the task
- A markdown file will be output in
<jacoco-report-directory>/jacocoSummary.md
task myJacocoMarkdown(type: jp.gr.java_conf.spica.plugin.gradle.jacoco.JacocoMarkdownTask) {
jacocoReportTask your_JacocoReport_task // auto configuration for the JacocoReportTask
}
For default task:
jacocoMarkdown {
diffEnabled false // default true
stdout false // default true
classListEnabled false // default true
classListCondition {
limit = 2 // default is 5, 0 means no limit
excludes = [ // default is empty
"com.example.MyClass", // when a class name exact matches this value, the class will be exclude
"/com.example.exclude.package.*/" // regex can be used with "/regex/" style
]
branchCoverageLessThan = 90 // default is 0, 0 means no filter by coverage
}
}
For a specific task:
myJacocoMarkdown {
jacocoXml file("path-to-jacoco-xml")
diffEnabled false
stdout false
classListEnabled false
classListCondition {
limit = 2
excludes = [
"com.example.MyClass",
"/com.example.exclude.package.*/"
]
branchCoverageLessThan = 90
}
previousJson file("path-to-a-base-json-to-show-the-coverage-changes")
targetTypes(["INSTRUCTION", "BRANCH", "LINE", "COMPLEXITY", "METHOD", "CLASS"])
outputJson file("path-to-output-json")
outputMd file("path-to-markdown")
}
See CHANGELOG.md