Jacoco Badge Gradle Plugin aims to analyze Jacoco Test Coverage Report and update the README file in your Java project with the badge link generated by Shields IO to reflect your code coverage on code change.
- Add this plugin in your
build.gradle
plugins {
id 'java'
id 'jacoco'
id 'com.github.dawnwords.jacoco.badge'
}
- Put the badge link placeholder in your
README.md
# Your Project Name
some basic description
### code coverages
![LINE](http://line.coverage.link)
![BRANCH](http://branch.coverage.link)
![COMPLEXITY](http://complexity.link)
### some other introductions
Note that by default the README.md
file should be placed in the project root directory together
with your build.gradle
file.
- Execute generate jacoco badge task after jacoco report task
./gradlew jacocoTestReport generateJacocoBadge
then you'll see the coverage link in your README.md
is automatically updated based on your jacoco
coverage report shown as following
![LINE](https://img.shields.io/badge/line--coverage-87%25-brightgreen.svg)
![BRANCH](https://img.shields.io/badge/branch--coverage-78%25-yellow.svg)
![COMPLEXITY](https://img.shields.io/badge/complexity-1.90-brightgreen.svg)
There's a configuration point for this plugin: jacocoBadgeGenSetting
in your build.gradle
.
You can manually specify jacocoReportPath
, readmePath
and limit
and their default value is shown
as following:
jacocoBadgeGenSetting {
jacocoReportPath "$buildDir/reports/jacoco/test/jacocoTestReport.xml"
readmePath "$projectDir/README.md"
// since v0.2.0, percentage limitation (0-100) for different type of coverage
limit = ['instruction': 0, 'branch': 0, 'line': 0, 'method': 0, 'class': 0]
}
Jacoco gives us 6 coverage metrics in its test report, namely INSTRUCTION
, BRANCH
, LINE
,
COMPLEXITY
, METHOD
and CLASS
. Your badge link should be place within a new line and
the alt
part should be one of the 6 values so that this plugin can detect them.