https://github.com/surpsg/diff-coverage-maven-plugin
Maven plugin for computing code coverage on modified code
https://github.com/surpsg/diff-coverage-maven-plugin
code-coverage coverage diff diff-coverage jacoco java kotlin maven maven-plugin
Last synced: about 23 hours ago
JSON representation
Maven plugin for computing code coverage on modified code
- Host: GitHub
- URL: https://github.com/surpsg/diff-coverage-maven-plugin
- Owner: SurpSG
- License: mit
- Created: 2020-06-23T21:14:55.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2025-06-23T23:01:10.000Z (5 days ago)
- Last Synced: 2025-06-28T00:01:51.966Z (about 23 hours ago)
- Topics: code-coverage, coverage, diff, diff-coverage, jacoco, java, kotlin, maven, maven-plugin
- Language: Kotlin
- Homepage:
- Size: 230 KB
- Stars: 22
- Watchers: 1
- Forks: 6
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# diff-coverage-maven-plugin
[](https://github.com/SurpSG/diff-coverage-maven-plugin/actions/workflows/release.yml)
[](https://search.maven.org/search?q=g:%22com.github.surpsg%22%20AND%20a:%22diff-coverage-maven-plugin%22)
[](https://codecov.io/gh/SurpSG/diff-coverage-maven-plugin)`Diff coverage maven plugin` builds [JaCoCo](https://github.com/jacoco/jacoco) compatible code coverage report of new and modified code based on a provided [diff](https://en.wikipedia.org/wiki/Diff#Unified_format).
The plugin is able to check and fail a build if code coverage rules are not met.
## How it works
`Diff coverage` works in tandem with JaCoCo and requires JaCoCo to be applied to a project as well.
The plugin does the next steps:
* analyzes coverage data('.exec' files generated by JaCoCo)
* cuts off all code coverage data that wasn't modified
* checks violation rules if any are set up
* builds diff coverage HTML report. See [HTML report example](#Report-example)## Install plugin
```xml
org.jacoco
jacoco-maven-plugin
0.8.10
io.github.surpsg
diff-coverage-maven-plugin
1.0.0
path/to/diffFile
HEAD
http://url.com
true
0.7
0.1
0.7
1.0
**/custom/exec/location/*.exec
**/custom/**/exclude/*.exec
**/package/**
**/ClassNamePrefix*
**/exclude/**/ClassName.class
html
false
diffCoverage
```
## Maven goal description
`Diff Coverage Maven plugin` has a single goal `diffCoverage` that is bind to `verify` phase
```shell script
# run tests and build diff coverage report
mvn clean verify# Invoke the goal explicitly.
# It depends on `test` phase, make sure it's called when coverage data(*.exec files) already generated.
mvn clean test diff-coverage:diffCoverage
```## Report example
Maven output on failed violation rules:
```
[INFO] File src/main/kotlin/org/example/Hello.kt has 5 modified lines
[INFO] New violation: Rule violated for bundle untitled: instructions covered ratio is 0.4, but expected minimum is 0.7
[INFO] New violation: Rule violated for bundle untitled: lines covered ratio is 0.6, but expected minimum is 0.7
[WARNING] Fail on violations: true. Found violations: 2.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.919 s
[INFO] Finished at: 2020-07-06T00:56:33+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Rule violated for bundle TestProj: instructions covered ratio is 0.4, but expected minimum is 0.7
[ERROR] Rule violated for bundle TestProj: lines covered ratio is 0.6, but expected minimum is 0.7
```
The plugin creates JaCoCo like HTML, XML and CSV reports in directory `target/site/diffCoverage/`.
JaCoCo HTML report
![]()