Skip to content

Commit fb884e7

Browse files
committed
Release 1.4.0 (#32)
- Support for Android Gradle Plugin 4.1 (although version 1.3.0 also works fine with AGP 4.1). - Support for per module code coverage, generate a module specific report by running `./gradlew yourModule:coverageReport`. - New configuration option `includeNoLocationClasses` which (like the name implies) sets Jacoco's `includeNoLocationClasses`. This makes using the plugin in combination with Robolectric easier, since Robolectric often requires `includeNoLocationClasses` to be set to `true`. - The "Jacoco has been automatically applied" message is not longer a warning but now an info message.
1 parent 0fd50e1 commit fb884e7

File tree

2 files changed

+122
-103
lines changed

2 files changed

+122
-103
lines changed

README.md

Lines changed: 121 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
[![Build](https://github.com/NeoTech-Software/Android-Root-Coverage-Plugin/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/NeoTech-Software/Android-Root-Coverage-Plugin/actions/workflows/build.yml)
44

55
# Android-Root-Coverage-Plugin
6-
**A Gradle plugin for combined code coverage reports for Android projects.**
7-
Generating code coverage reports for Android Projects is in most cases quite easy. Unfortunately by
8-
default (using Jacoco) code coverage is generated separately per module. This means each module
9-
takes into account it's own sources and tests (which is in terms of domain separation fine). However
10-
it is very common to find multi-module Android projects where only one module actually has tests.
11-
This plugin comes in handy for those projects. It generates code coverage reports using Jacoco
12-
taking into account all the modules and tests at once, or in other words: code in module B will show
13-
up as "covered" when tests in Module A touch it.
14-
15-
- Supports both Android app and library modules (`com.android.application` & `com.android.library`).
16-
- Supports different build variants per module within the same report.
17-
- Supports custom package/class filters.
6+
**Automatically configures Jacoco code coverage tasks for both combined and per module coverage reports.**
7+
8+
Configuring Jacoco for Android projects is unfortunately not always easy. It is very common to find multi-module Android
9+
projects where one module has tests for code found in another module, for example integration/UI tests that cover code
10+
in multiple other modules. Configuring Jacoco for such a case is not always straight forward, you need to point Jacoco
11+
to the right sources, execution data and class files, not to mention how error prone manual Jacoco setups can be. This
12+
plugin automatically configures Jacoco for you, so you don't have to.
13+
14+
**Feature highlights:**
15+
- Include unit-tests, instrumented unit-tests or both in the final reports
16+
- Support for combined coverage reports *(code in module X is covered when touched by tests from any other module)*
17+
- Support for coverage reports per module *(code in module X is only covered when touched by tests from module X)*
18+
- Custom package/class filters
19+
- Support for mixed build-types
1820

1921
> Notice: Due to the [shutdown of Bintray/JCenter](https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/)
2022
> the Android-Root-Coverage-Plugin has been migrated
@@ -32,126 +34,143 @@ up as "covered" when tests in Module A touch it.
3234
> }
3335
> ```
3436
>
35-
> The current version has been re-released with the new group ID and plugin ID to Maven Central and
36-
> the Gradle Plugin Portal (1.3.1), new versions will also be released to these repositories. See
37-
> the 'Setup' section of this readme on how to use this plugin with the updated group ID and
38-
> plugin ID.
37+
> Version 1.3.0 has been re-released (as 1.3.1) with the new group ID and plugin ID to Maven Central and
38+
> the Gradle Plugin Portal. Upcoming versions will also be released to these repositories. Check the
39+
> [setup](#1-setup) section on how to use this plugin with the updated group ID and plugin ID.
3940
40-
# Setup
41-
Apply the Android-Root-Coverage-Plugin plugin to your top-level (root project) gradle file:
4241
43-
```groovy
44-
// Step 2: Apply the plugin to the top-level gradle file
45-
apply plugin: 'nl.neotech.plugin.rootcoverage'
42+
# 1. Setup
43+
Apply the plugin to your top-level (root project) `build.gradle` file using one of the
44+
following methods:
4645
47-
buildscript {
48-
dependencies {
49-
// Step 1: add the dependency
50-
classpath 'nl.neotech.plugin:android-root-coverage-plugin:1.3.1'
51-
}
52-
}
53-
```
46+
<details open>
47+
<summary><strong>Plugin block:</strong></summary>
5448
49+
```groovy
50+
// Below buildscript {}
51+
plugins {
52+
id "nl.neotech.plugin.rootcoverage" version "1.4.0"
53+
}
54+
```
55+
</details>
5556
56-
# How to use
57-
Currently only modules with the plugin type `com.android.application` or `com.android.library` are
58-
taken into account when generating the coverage report, besides this any module that does not have
59-
`testCoverageEnabled true` for the selected build variant (by default: `debug`) will be skipped:
57+
<details>
58+
<summary><strong>classpath + apply:</strong></summary>
6059

61-
You can add a module by enabling `testCoverageEnabled`:
62-
```groovy
63-
android {
64-
buildTypes {
65-
debug {
66-
testCoverageEnabled true
67-
}
68-
}
60+
```groovy
61+
apply plugin: 'nl.neotech.plugin.rootcoverage'
62+
63+
buildscript {
64+
dependencies {
65+
classpath 'nl.neotech.plugin:android-root-coverage-plugin:1.4.0'
66+
}
6967
}
70-
```
68+
```
69+
</details>
7170

72-
The Android-Root-Coverage-Plugin generates a special Gradle task `:rootCodeCoverageReport` that when
73-
executed generates a Jacoco code coverage report. You can either run this task directly from
74-
Android Studio using the Gradle Tool Window (see:
75-
<https://www.jetbrains.com/help/idea/jetgradle-tool-window.html>) or from the terminal.
7671

77-
- **Gradle Tool Window:** You can find the task under: `Tasks > reporting > rootCodeCoverageReport`, double click to execute it.
78-
- **Terminal:** Execute the task using `gradlew rootCodeCoverageReport`.
72+
# 2. How to use
7973

74+
1. Enable running tests with coverage in the desired modules:
8075

81-
# Compatibility
82-
| Version | Android Gradle plugin version | Gradle version |
83-
| ------------- | ----------------------------- | -------------- |
84-
| **1.3.1** | 3.6 | 5.6.4+ |
85-
| **1.2.1** | 3.5 | 5.4.1+ |
86-
| **1.1.2** | 3.4 | 5.1.1+ |
87-
| **1.1.1** | 3.3 | 4.10.1+ |
88-
| **1.0.2** | 3.2 | 4.6+ |
76+
```groovy
77+
android {
78+
buildTypes {
79+
debug {
80+
testCoverageEnabled true
81+
}
82+
}
83+
}
84+
```
8985

90-
*Note: Versions below 1.3.1, such as 1.3.0, are only available on the Gradle Plugin Portal
91-
(`maven { url "https://plugins.gradle.org/m2/"}`) and not on Maven Central. These versions use the
92-
group ID `org.neotech.plugin` and plugin ID `org.neotech.plugin.rootcoverage`!*
86+
> Only Android modules (`com.android.application` or `com.android.library`) are supported, this plugin will not execute
87+
tests and generate coverage reports for non-android modules. Also any Android module that does not have
88+
> `testCoverageEnabled true` for the desired coverage variant (default: `debug`) will be ignored.
9389
94-
*Note: This plugin normally supports exactly the same Gradle versions as the Android Gradle
95-
plugin, for more information please refer to:*
96-
<https://developer.android.com/studio/releases/gradle-plugin#updating-gradle>
90+
2. Run one of the automatically configured Gradle tasks to generate a Jacoco report:
91+
- **For combined coverage:** `./gradlew :coverageReport`
92+
- **For module specific coverage:** `./gradlew :yourModule:coverageReport`
9793

98-
Android Gradle Plugin versions before `3.4.0-alpha05` are affected by a bug that in certain conditions can
99-
cause Jacoco instrumentation to fail in combination with inline kotlin methods shared across modules. For more information
100-
see: <https://issuetracker.google.com/issues/109771903> and <https://issuetracker.google.com/issues/110763361>.
101-
If your project is affected by this upgrade to an Android Gradle Plugin version of at least `3.4.0-alpha05`.
94+
> Resulting reports can be found in `/build/reports/` and `yourModule/build/reports/`
95+
96+
3. Optionally configure the plugin to change the output types, test variants and more, see
97+
[Configuration](#3-configuration).
10298

10399

104-
# Configuration
100+
# 3. Configuration
105101
By default the plugin generates code coverage reports using the build variant `debug` for every
106102
module. However in some cases different build variants per module might be required, especially if
107103
there is no `debug` build variant available. In those cases you can configure custom build variants
108104
for specific modules:
109105

110106
```groovy
111107
rootCoverage {
112-
// The default build variant for every module
113-
buildVariant "debug"
114-
// Overrides the default build variant for specific modules.
115-
buildVariantOverrides ":moduleA" : "debugFlavourA", ":moduleB": "debugFlavourA"
116-
117-
// Class exclude patterns
118-
excludes = ["**/some.package/**"]
119-
120-
// Since 1.1 generateHtml is by default true
121-
generateCsv false
122-
generateHtml true
123-
generateXml false
124-
125-
// Since 1.2: When false the plugin does not execute any tests, useful when you run the tests manually or remote (Firebase Test Lab)
126-
executeTests true
127-
128-
// Since 1.2: Same as executeTests except that this only affects the instrumented Android tests
129-
executeAndroidTests true
130-
131-
// Since 1.2: Same as executeTests except that this only affects the unit tests
132-
executeUnitTests true
133-
134-
// Since 1.2: When true include results from instrumented Android tests into the coverage report
135-
includeAndroidTestResults true
136-
137-
// Since 1.2: When true include results from unit tests into the coverage report
138-
includeUnitTestResults true
108+
// The default build variant for every module
109+
buildVariant "debug"
110+
// Overrides the default build variant for specific modules.
111+
buildVariantOverrides ":moduleA" : "debugFlavourA", ":moduleB": "debugFlavourA"
112+
113+
// Class & package exclude patterns
114+
excludes = ["**/some.package/**"]
115+
116+
// Since 1.1 generateHtml is by default true
117+
generateCsv false
118+
generateHtml true
119+
generateXml false
120+
121+
// Since 1.2: When false the plugin does not execute any tests, useful when you run the tests manually or remote (Firebase Test Lab)
122+
executeTests true
123+
124+
// Since 1.2: Same as executeTests except that this only affects the instrumented Android tests
125+
executeAndroidTests true
126+
127+
// Since 1.2: Same as executeTests except that this only affects the unit tests
128+
executeUnitTests true
129+
130+
// Since 1.2: When true include results from instrumented Android tests into the coverage report
131+
includeAndroidTestResults true
132+
133+
// Since 1.2: When true include results from unit tests into the coverage report
134+
includeUnitTestResults true
135+
136+
// Since 1.4: Sets jacoco.includeNoLocationClasses, so you don't have to. Helpful when using Robolectric
137+
// which usually requires this attribute to be true
138+
includeNoLocationClasses false
139139
}
140140
```
141141

142142

143-
# Development
144-
Want to contribute? Great! Currently this plugin is mainly in need of extensive testing in some more
145-
projects. But if you like to add some actually functionality, this is the wish list:
143+
# 4. Compatibility
144+
| Version | Android Gradle plugin version | Gradle version |
145+
| ------------- | ----------------------------- | ----------------- |
146+
| **1.4.0** | 4.1+ | 6.5+ |
147+
| **1.3.1** | 4.0<br/>3.6 | 6.1.1+<br/>5.6.4+ |
148+
| **1.2.1** | 3.5 | 5.4.1+ |
149+
| **1.1.2** | 3.4 | 5.1.1+ |
150+
| **1.1.1** | 3.3 | 4.10.1+ |
151+
| **1.0.2** | 3.2 | 4.6+ |
152+
153+
> *Note 1: Plugin versions below 1.3.1, such as 1.3.0, are only available on the Gradle Plugin Portal
154+
(`maven { url "https://plugins.gradle.org/m2/"}`) and not on Maven Central. These versions use the
155+
group ID `org.neotech.plugin` and plugin ID `org.neotech.plugin.rootcoverage`!*
156+
157+
> *Note 2: This plugin normally supports the same Gradle versions as the Android Gradle plugin, for more information
158+
> see:* <https://developer.android.com/studio/releases/gradle-plugin#updating-gradle>
159+
160+
> Note 3: Android Gradle Plugin versions before `3.4.0-alpha05` are affected by a bug that in certain conditions can
161+
cause Jacoco instrumentation to fail in combination with inline kotlin methods shared across modules. For more information
162+
see: <https://issuetracker.google.com/issues/109771903> and <https://issuetracker.google.com/issues/110763361>.
163+
If your project is affected by this upgrade to an Android Gradle Plugin version of at least `3.4.0-alpha05`.
164+
146165

147-
- Support for Java library modules
148-
- Make use of the JacocoMerge task? To merge the `exec` en `ec` files?
149-
- Improved integration test setup: without the hackish dynamic versions in the Gradle plugin block?
166+
# 5. Development
167+
Want to contribute? Great! Just clone the repo, code away and create a pull-request. Try to keep changes small and make
168+
sure to follow the code-style as found in the rest of the project.
150169

151170
**How to test your changes/additions?**
152171
The plugin comes with an integration test. You can run this test either by executing
153-
`gradlew clean test` or run the test directly from Android Studio (or IntelliJ IDEA).
172+
`./gradlew clean test` or run the test directly from Android Studio (or IntelliJ IDEA).
154173

155174

156-
# Author note
157-
Many thanks to [Hans van Dam](https://github.com/hansvdam) for helping with testing and the initial idea.
175+
# 6. Honorable mentions
176+
Many thanks to [Hans van Dam](https://github.com/hansvdam) for helping with testing and the initial idea.

plugin/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
POM_ARTIFACT_ID=android-root-coverage-plugin
2-
VERSION_NAME=1.3.1
2+
VERSION_NAME=1.4.0
33
POM_NAME=Android Root Coverage Plugin
44
POM_DESCRIPTION=A Gradle plugin for easy generation of combined code coverage reports for Android projects with multiple modules.

0 commit comments

Comments
 (0)