A Gradle plugin that adds fully configured JacocoReport
tasks for unit tests of each Android application and library project variant. See the readme for the original plugin here.
This is the fork of jacoco-android-gradle-plugin by arturdm
This plugin fixes the changes related to report configs, that breaks the build for the original plugin (v0.1.5) Gradle 8+. The changes can be found in this commit.
buildscript {
repositories {
...
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
...
classpath 'io.github.kevalpatel2106.gradle:jacoco-android:0.1.5'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.github.kevalpatel2106.gradle.jacoco-android'
jacoco {
toolVersion = "0.8.4"
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
android {
...
productFlavors {
free {}
paid {}
}
}
The above configuration creates a JacocoReport
task for each variant and an additional jacocoTestReport
task that runs all of them.
jacocoTestPaidDebugUnitTestReport
jacocoTestFreeDebugUnitTestReport
jacocoTestPaidReleaseUnitTestReport
jacocoTestFreeReleaseUnitTestReport
jacocoTestReport
The plugin excludes Android generated classes from report generation by default. You can use jacocoAndroidUnitTestReport
extension to add other exclusion patterns if needed.
jacocoAndroidUnitTestReport {
excludes += ['**/AutoValue_*.*',
'**/*JavascriptBridge.class']
}
You can also toggle report generation by type using the extension.
jacocoAndroidUnitTestReport {
csv.required false
xml.required true
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
By default your report will be in [root_project]/[project_name]/build/jacoco/
But you can change the local reporting directory :
jacocoAndroidUnitTestReport {
destination "/path/to/the/new/local/directory/"
}
To generate all reports run:
$ ./gradlew jacocoTestReport
Reports for each variant are available at $buildDir/reports/jacoco
in separate subdirectories, e.g. build/reports/jacoco/jacocoTestPaidDebugUnitTestReport
.