Skip to content

SurpSG/offlins-gradle-plugin

Repository files navigation

offlins-gradle-plugin

Gradle Plugin Portal Main branch codecov GitHub issues GitHub stars

Offlins is similar to standard Gradle JaCoCo plugin but uses JaCoCo tool in offline instrumentation mode. This plugin is useful if PowerMock is used in tests.

Compatibility

Compatibility table:

Offlins plugin Gradle
0.3.0 6.1 - 8.+
0.2.1.+ 5.1 - 7.6.+

Installation

The plugin is published to Gradle plugins.

Groovy
plugins {
    id "io.github.surpsg.offlins" version "0.3.0"
}
Kotlin
plugins {
    id("io.github.surpsg.offlins") version "0.3.0"
}

Configuration

All properties are optional but have the following defaults:

  • JaCoCo version 0.8.8
  • HTML report is enabled with dafault path build/reports/jacoco/html
  • XML report is disabled with dafault path build/reports/jacoco/coverageReport.xml
  • CSV report is disabled with dafault path build/reports/jacoco/coverageReport.csv
Groovy
offlinsCoverage {
    jacocoVersion = '0.8.7' // Optional. By default `0.8.8`

    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`    
    }
}
Kotlin
configure<io.github.surpsg.offlins.OfflinsExtension> {
    jacocoVersion = "0.8.7" // Optional. By default `0.8.8`

    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:

 ./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/<project-name>-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)

Offlins plugin modifies default test task from Java plugin:

  • 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