Gradle Android Jacoco Plugin

Gradle plugin that generates Jacoco reports from an Android Gradle Project.

License

License

Categories

Categories

Gradle Build Tools JUnit Unit Testing JaCoCo Application Testing & Monitoring Code Coverage
GroupId

GroupId

com.vanniktech
ArtifactId

ArtifactId

gradle-android-junit-jacoco-plugin
Last Version

Last Version

0.16.0
Release Date

Release Date

Type

Type

jar
Description

Description

Gradle Android Jacoco Plugin
Gradle plugin that generates Jacoco reports from an Android Gradle Project.
Project URL

Project URL

http://github.com/vanniktech/gradle-android-junit-jacoco-plugin/
Source Code Management

Source Code Management

http://github.com/vanniktech/gradle-android-junit-jacoco-plugin/

Download gradle-android-junit-jacoco-plugin

How to add to project

<!-- https://jarcasting.com/artifacts/com.vanniktech/gradle-android-junit-jacoco-plugin/ -->
<dependency>
    <groupId>com.vanniktech</groupId>
    <artifactId>gradle-android-junit-jacoco-plugin</artifactId>
    <version>0.16.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.vanniktech/gradle-android-junit-jacoco-plugin/
implementation 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.16.0'
// https://jarcasting.com/artifacts/com.vanniktech/gradle-android-junit-jacoco-plugin/
implementation ("com.vanniktech:gradle-android-junit-jacoco-plugin:0.16.0")
'com.vanniktech:gradle-android-junit-jacoco-plugin:jar:0.16.0'
<dependency org="com.vanniktech" name="gradle-android-junit-jacoco-plugin" rev="0.16.0">
  <artifact name="gradle-android-junit-jacoco-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.vanniktech', module='gradle-android-junit-jacoco-plugin', version='0.16.0')
)
libraryDependencies += "com.vanniktech" % "gradle-android-junit-jacoco-plugin" % "0.16.0"
[com.vanniktech/gradle-android-junit-jacoco-plugin "0.16.0"]

Dependencies

test (4)

Group / Artifact Type Version
com.android.tools.build : gradle jar 3.4.0
org.jetbrains.kotlin : kotlin-gradle-plugin jar 1.3.31
junit : junit jar 4.13-beta-2
org.spockframework : spock-core jar 1.1-groovy-2.4

Project Modules

There are no modules declared in this project.

gradle-android-junit-jacoco-plugin

Gradle plugin that generates Jacoco reports from a Gradle Project. Android Application, Android Library, Kotlin and Java Plugins are supported by this plugin. When this plugin is applied it goes over every subproject and creates the corresponding Jacoco tasks.

Android project

JVM Unit-Tests

  • Task jacocoTestReport<Flavor><BuildType>
    • Executes the test<Flavor><BuildType>UnitTest task before
    • Gets executed when the check task is executed
    • Generated Jacoco reports can be found under build/reports/jacoco/<Flavor>/<BuildType>.

Instrumented tests

  • Task combinedTestReport<Flavor><BuildType>
    • Executes the test<Flavor><BuildType>UnitTest and create<Flavor><BuildType>CoverageReports tasks before (JVM and instrumented tests)
    • Gets executed when the check task is executed
    • Generated Jacoco reports can be found under build/reports/jacocoCombined/<Flavor>/<BuildType>. Note that this task is only generated, if you set testCoverageEnabled = true for your build type, e.g.
android {
  buildTypes {
    debug {
      testCoverageEnabled true
    }
  }
}

Where <BuildType> is usually debug & release unless additional build types where specified. <Flavor> is optional and will be ignored if not specified.

For instance when having debug & release build types and no flavors the following tasks would be created: jacocoTestReportDebug and jacocoTestReportRelease.

When having debug & release build types and red & blue flavors the following tasks would be created: jacocoTestReportRedDebug, jacocoTestReportBlueDebug, jacocoTestReportRedRelease and jacocoTestReportBlueRelease.

Java project

  • Task jacocoTestReport
    • Executes the test task before
    • Gets executed when the check task is executed
    • Generated Jacoco reports can be found under build/reports/jacoco/.

In addition the plugin generates mergeJacocoReports & jacocoTestReportMerged tasks.

mergeJacocoReports will merge all of the jacoco reports together.

jacocoTestReportMerged will output an xml and html file for the merged report.

Works with the latest Gradle Android Tools version 3.4.0. This plugin is compiled using Java 7 hence you also need Java 7 in order to use it.

Set up

root/build.gradle

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath "com.vanniktech:gradle-android-junit-jacoco-plugin:0.16.0"
  }
}

apply plugin: "com.vanniktech.android.junit.jacoco"

Information: This plugin is also available on Gradle plugins

Snapshot

buildscript {
  repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
  }
  dependencies {
    classpath "com.vanniktech:gradle-android-junit-jacoco-plugin:0.17.0-SNAPSHOT"
  }
}

apply plugin: "com.vanniktech.android.junit.jacoco"

Configuration

Those are all available configurations - shown with default values and their types. More information can be found in the Java Documentation of the Extension.

junitJacoco {
  jacocoVersion = '0.8.2' // type String
  ignoreProjects = [] // type String array
  excludes // type String List
  includeNoLocationClasses = false // type boolean
  includeInstrumentationCoverageInMergedReport = false // type boolean
  xml.enabled = true
  csv.enabled = true
  html.enabled = true
}

License

Copyright (C) 2015 Vanniktech - Niklas Baudy

Licensed under the Apache License, Version 2.0

Versions

Version
0.16.0
0.15.0
0.14.0
0.13.0
0.12.0
0.11.0
0.10.0
0.9.0
0.8.0
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0