An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# offlins-gradle-plugin

[![Gradle Plugin Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/io.github.surpsg/offlins-gradle-plugin/maven-metadata.xml.svg?label=Gradle%20Plugin%20Portal)](https://plugins.gradle.org/plugin/io.github.surpsg.offlins)
[![Main branch](https://github.com/SurpSG/offlins-gradle-plugin/actions/workflows/main-branch.yml/badge.svg)](https://github.com/SurpSG/offlins-gradle-plugin/actions/workflows/main-branch.yml)
[![codecov](https://codecov.io/gh/SurpSG/offlins-gradle-plugin/branch/main/graph/badge.svg?token=08EKXE7agx)](https://codecov.io/gh/SurpSG/offlins-gradle-plugin)
[![GitHub issues](https://img.shields.io/github/issues/SurpSG/offlins-gradle-plugin)](https://github.com/SurpSG/offlins-gradle-plugin/issues)
[![GitHub stars](https://img.shields.io/github/stars/SurpSG/offlins-gradle-plugin?style=flat-square)](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