https://github.com/surpsg/offlins-gradle-plugin
JaCoCo Gradle plugin
https://github.com/surpsg/offlins-gradle-plugin
coverage gradle gradle-plugin jacoco jacoco-offline-instrumentation jacoco-plugin jacoco-reports powermock
Last synced: 3 months ago
JSON representation
JaCoCo Gradle plugin
- Host: GitHub
- URL: https://github.com/surpsg/offlins-gradle-plugin
- Owner: SurpSG
- License: mit
- Created: 2022-05-04T21:10:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-06-24T14:12:36.000Z (4 months ago)
- Last Synced: 2025-06-28T00:07:48.845Z (3 months ago)
- Topics: coverage, gradle, gradle-plugin, jacoco, jacoco-offline-instrumentation, jacoco-plugin, jacoco-reports, powermock
- Language: Kotlin
- Homepage:
- Size: 419 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# offlins-gradle-plugin
[](https://plugins.gradle.org/plugin/io.github.surpsg.offlins)
[](https://github.com/SurpSG/offlins-gradle-plugin/actions/workflows/main-branch.yml)
[](https://codecov.io/gh/SurpSG/offlins-gradle-plugin)
[](https://github.com/SurpSG/offlins-gradle-plugin/issues)
[](https://github.com/SurpSG/offlins-gradle-plugin/stargazers)`Offlins` is similar to standard Gradle [JaCoCo plugin](https://docs.gradle.org/current/userguide/jacoco_plugin.html)
but uses [JaCoCo](https://www.eclemma.org/jacoco/) tool
in [offline instrumentation](https://www.jacoco.org/jacoco/trunk/doc/offline.html) mode.
This plugin is useful if [PowerMock](https://github.com/powermock/powermock) is used in tests.## Compatibility
Compatibility table:
| Offlins plugin | Gradle |
|----------------|---------------------|
| **0.6.0** | **8.11** - **8.12** |
| **0.5.0** | **8.11** - **8.12** |
| **0.4.0** | **6.1** - **8.7** |
| **0.3.0** | **6.1** - **8.7** |
| **0.2.1.+** | **5.1** - **7.6** |## Installation
The plugin is published to [Gradle plugins](https://plugins.gradle.org/plugin/io.github.surpsg.offlins).
Groovy
```groovy
plugins {
id "io.github.surpsg.offlins" version "0.6.0"
}
```Kotlin
```kotlin
plugins {
id("io.github.surpsg.offlins") version "0.6.0"
}
```## Configuration
All properties are **optional** but have the following defaults:
* JaCoCo version `0.8.12`
* *HTML* report is **disabled** with dafault path `build/reports/jacoco/html`
* *XML* report is **disabled** with dafault path `build/reports/jacoco/report.xml`
* *CSV* report is **disabled** with dafault path `build/reports/jacoco/report.csv`Kotlin
```kotlin
configure {
jacocoVersion = "0.8.7" // Optional. By default `0.8.12`reports {
html.enabled.set(true) // Optional. By default `true`
html.location.set(project.file("build/custom/html")) // Optional. By default `build/reports/jacoco/html`xml.enabled.set(true) // Optional. By default `false`
xml.location.set(project.file("build/custom/xmlCoverage.xml")) // Optional. By default `build/reports/jacoco/coverageReport.xml`csv.enabled.set(true) // Optional. By default `false`
csv.location.set(project.file("build/custom/csvCoverage.csv")) // Optional. By default `build/reports/jacoco/coverageReport.csv`// Optional. By default `emptyList()`
excludeClasses.set(
listOf(
"**/path/to/*/ExcludedClass*",
"**/ExcludedClass2.class"
)
)
}
}
```Groovy
```groovy
offlinsCoverage {
jacocoVersion = '0.8.7' // Optional. By default `0.8.12`reports {
html.enabled.set true // Optional. By default `true`
html.location.set project.file('build/custom/html') // Optional. By default `build/reports/jacoco/html`xml.enabled.set true // Optional. By default `false`
xml.location.set project.file('build/custom/xmlCoverage.xml')
// Optional. By default `build/reports/jacoco/coverageReport.xml`csv.enabled.set true // Optional. By default `false`
csv.location.set project.file('build/custom/csvCoverage.csv')
// Optional. By default `build/reports/jacoco/coverageReport.csv`
}
}
```## Excecute
Run tests by task `test` and generate reports by taks `coverageReport`:
```bash
./gradlew test coverageReport
```## Tasks description
* `instrumentClassesOffline` - instruments `.class` files
* Inputs: class files generated by `classes` task
* Outputs: instrumented classes in `build/classes-instrumented`
* Depends on `classes` task
* `assembleInstrumentedJar` - generates jar file from instrumented classes
* Inputs: insrumented class files generated by `instrumentClassesOffline` task
* Outputs: jar file classes in `libs/-instrumented.jar`
* Depends on `instrumentClassesOffline` task
* `coverageReport` - generates coverage reports
* Inputs: `.exec` file generated by `test` task
* Outputs: HTML, XML, CSV reports(depends on [plugin configuration](#configuration))`Offlins` plugin modifies
default [test task](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html)
from [Java plugin](https://docs.gradle.org/current/userguide/java_plugin.html):* Sets the `test` task to dependend on `instrumentClassesOffline`
* Adds **org.jacoco:org.jacoco.agent** artifact to classpath
* Replaces a project `.class` files with instrumented classes in classpath
* Replaces jars(dependecies on subprojects) with instrumented jars in classpath