3
3
[ ![ 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 )
4
4
5
5
# 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
18
20
19
21
> Notice: Due to the [ shutdown of Bintray/JCenter] ( https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/ )
20
22
> the Android-Root-Coverage-Plugin has been migrated
@@ -32,126 +34,143 @@ up as "covered" when tests in Module A touch it.
32
34
> }
33
35
> ```
34
36
>
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.
39
40
40
- # Setup
41
- Apply the Android-Root-Coverage-Plugin plugin to your top-level (root project) gradle file:
42
41
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:
46
45
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>
54
48
49
+ ```groovy
50
+ // Below buildscript {}
51
+ plugins {
52
+ id "nl.neotech.plugin.rootcoverage" version "1.4.0"
53
+ }
54
+ ```
55
+ </details>
55
56
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 >
60
59
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
+ }
69
67
}
70
- ```
68
+ ```
69
+ </details >
71
70
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.
76
71
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
79
73
74
+ 1 . Enable running tests with coverage in the desired modules:
80
75
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
+ ```
89
85
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.
93
89
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 `
97
93
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 ) .
102
98
103
99
104
- # Configuration
100
+ # 3. Configuration
105
101
By default the plugin generates code coverage reports using the build variant ` debug ` for every
106
102
module. However in some cases different build variants per module might be required, especially if
107
103
there is no ` debug ` build variant available. In those cases you can configure custom build variants
108
104
for specific modules:
109
105
110
106
``` groovy
111
107
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
139
139
}
140
140
```
141
141
142
142
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
+
146
165
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.
150
169
151
170
** How to test your changes/additions?**
152
171
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).
154
173
155
174
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.
0 commit comments