Skip to content

Commit 88ea25e

Browse files
committed
Update: Readme to include Gradle Kotlin examples
1 parent 5ef57a1 commit 88ea25e

File tree

1 file changed

+157
-62
lines changed

1 file changed

+157
-62
lines changed

README.md

+157-62
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,33 @@ Apply the plugin to your top-level (root project) `build.gradle` file using one
2424
following methods:
2525

2626
<details open>
27-
<summary><strong>Plugin block:</strong></summary>
27+
<summary><strong>Plugin block (Kotlin):</strong></summary>
28+
29+
```kotlin
30+
plugins {
31+
// Add the plugin to the plugin block
32+
id("nl.neotech.plugin.rootcoverage") version "1.9.0"
33+
}
34+
```
35+
</details>
36+
37+
<details>
38+
<summary><strong>Plugin block (Groovy):</strong></summary>
2839

2940
```groovy
30-
// Below buildscript {}
3141
plugins {
32-
id "nl.neotech.plugin.rootcoverage" version "1.9.0"
42+
// Add the plugin to the plugin block
43+
id "nl.neotech.plugin.rootcoverage" version "1.9.0"
3344
}
3445
```
3546
</details>
3647

48+
<blockquote>
49+
3750
<details>
38-
<summary><strong>classpath + apply:</strong></summary>
51+
<summary><strong>Still using classpath & apply?</strong></summary>
3952

53+
**Groovy**
4054
```groovy
4155
apply plugin: 'nl.neotech.plugin.rootcoverage'
4256
@@ -47,7 +61,7 @@ following methods:
4761
}
4862
```
4963
</details>
50-
64+
</blockquote>
5165

5266
# 2. How to use
5367

@@ -56,6 +70,28 @@ following methods:
5670
modules that have at least one of these properties enabled in the final report (or individual
5771
reports)
5872

73+
<details open>
74+
<summary><strong>Kotlin</strong> (.gradle.kts)</summary>
75+
76+
```kotlin
77+
android {
78+
buildTypes {
79+
debug {
80+
// AGP 7.3+ (at least one should be true for this module to be included in the reporting)
81+
enableUnitTestCoverage = true
82+
enableAndroidTestCoverage = true
83+
84+
// AGP before 7.3
85+
testCoverageEnabled = true
86+
}
87+
}
88+
}
89+
```
90+
</details>
91+
92+
<details>
93+
<summary><strong>Groovy</strong> (.gradle)</summary>
94+
5995
```groovy
6096
android {
6197
buildTypes {
@@ -70,6 +106,7 @@ following methods:
70106
}
71107
}
72108
```
109+
</details>
73110

74111
> Only Android modules (`com.android.application` or `com.android.library`) are supported, this plugin will not execute
75112
tests and generate coverage reports for non-android modules. Also keep in mind that by default
@@ -93,86 +130,137 @@ module. However in some cases different build variants per module might be requi
93130
there is no `debug` build variant available. In those cases you can configure custom build variants
94131
for specific modules:
95132

96-
```groovy
97-
rootCoverage {
98-
// The default build variant for every module
99-
buildVariant "debug"
100-
// Overrides the default build variant for specific modules.
101-
buildVariantOverrides ":moduleA" : "debugFlavourA", ":moduleB": "debugFlavourA"
102-
103-
// Class & package exclude patterns
104-
excludes = ["**/some.package/**"]
105-
106-
// Since 1.1 generateHtml is by default true
107-
generateCsv false
108-
generateHtml true
109-
generateXml false
133+
>**Place this in the project root build.gradle file!**
110134
111-
// Since 1.2: Same as executeTests except that this only affects the instrumented Android tests
112-
executeAndroidTests true
113-
114-
// Since 1.2: Same as executeTests except that this only affects the unit tests
115-
executeUnitTests true
135+
<details open>
136+
<summary><strong>Kotlin</strong> (.gradle.kts)</summary>
137+
138+
```kotlin
139+
rootCoverage {
140+
// The default build variant for every module
141+
buildVariant = "debug"
142+
// Overrides the default build variant for specific modules.
143+
buildVariantOverrides = mapOf(":moduleA" to "debugFlavourA", ":moduleB" to "debugFlavourA")
144+
145+
// Class & package exclude patterns
146+
excludes = ["**/some.package/**"]
147+
148+
// Since 1.1 generateHtml is by default true
149+
generateCsv = false
150+
generateHtml = true
151+
generateXml = false
152+
153+
// Since 1.2: Same as executeTests except that this only affects the instrumented Android tests
154+
executeAndroidTests = true
155+
156+
// Since 1.2: Same as executeTests except that this only affects the unit tests
157+
executeUnitTests = true
158+
159+
// Since 1.2: When true include results from instrumented Android tests into the coverage report
160+
includeAndroidTestResults = true
161+
162+
// Since 1.2: When true include results from unit tests into the coverage report
163+
includeUnitTestResults = true
164+
165+
// Since 1.4: Sets jacoco.includeNoLocationClasses, so you don't have to. Helpful when using Robolectric
166+
// which usually requires this attribute to be true
167+
includeNoLocationClasses = false
168+
169+
// Since 1.7 (experimental): If set to true instrumented tests will be attempt to run on
170+
// Gradle Managed Devices before trying devices connected through other means (ADB).
171+
runOnGradleManagedDevices = false
172+
173+
// Since 1.7 (experimental): The name of the Gradle Managed device to run instrumented tests on.
174+
// This is only used if `runOnGradleManagedDevices` is set to true. If not given tests will be
175+
// run on all available Gradle Managed Devices
176+
gradleManagedDeviceName = "nexusoneapi30"
177+
}
178+
```
179+
</details>
116180

117-
// Since 1.2: When true include results from instrumented Android tests into the coverage report
118-
includeAndroidTestResults true
181+
<details>
182+
<summary><strong>Groovy</strong> (.gradle)</summary>
119183

120-
// Since 1.2: When true include results from unit tests into the coverage report
121-
includeUnitTestResults true
184+
```groovy
185+
rootCoverage {
186+
// The default build variant for every module
187+
buildVariant "debug"
188+
// Overrides the default build variant for specific modules.
189+
buildVariantOverrides ":moduleA" : "debugFlavourA", ":moduleB": "debugFlavourA"
122190
123-
// Since 1.4: Sets jacoco.includeNoLocationClasses, so you don't have to. Helpful when using Robolectric
124-
// which usually requires this attribute to be true
125-
includeNoLocationClasses false
126-
127-
// Since 1.7 (experimental): If set to true instrumented tests will be attempt to run on
128-
// Gradle Managed Devices before trying devices connected through other means (ADB).
129-
runOnGradleManagedDevices false
191+
// Class & package exclude patterns
192+
excludes = ["**/some.package/**"]
130193
131-
// Since 1.7 (experimental): The name of the Gradle Managed device to run instrumented tests on.
132-
// This is only used if `runOnGradleManagedDevices` is set to true. If not given tests will be
133-
// run on all available Gradle Managed Devices
134-
gradleManagedDeviceName "nexusoneapi30"
135-
}
136-
```
137-
194+
// Since 1.1 generateHtml is by default true
195+
generateCsv false
196+
generateHtml true
197+
generateXml false
198+
199+
// Since 1.2: Same as executeTests except that this only affects the instrumented Android tests
200+
executeAndroidTests true
201+
202+
// Since 1.2: Same as executeTests except that this only affects the unit tests
203+
executeUnitTests true
204+
205+
// Since 1.2: When true include results from instrumented Android tests into the coverage report
206+
includeAndroidTestResults true
207+
208+
// Since 1.2: When true include results from unit tests into the coverage report
209+
includeUnitTestResults true
210+
211+
// Since 1.4: Sets jacoco.includeNoLocationClasses, so you don't have to. Helpful when using Robolectric
212+
// which usually requires this attribute to be true
213+
includeNoLocationClasses false
214+
215+
// Since 1.7 (experimental): If set to true instrumented tests will be attempt to run on
216+
// Gradle Managed Devices before trying devices connected through other means (ADB).
217+
runOnGradleManagedDevices false
218+
219+
// Since 1.7 (experimental): The name of the Gradle Managed device to run instrumented tests on.
220+
// This is only used if `runOnGradleManagedDevices` is set to true. If not given tests will be
221+
// run on all available Gradle Managed Devices
222+
gradleManagedDeviceName "nexusoneapi30"
223+
}
224+
```
225+
</details>
138226

139227
# 4. Compatibility
140228
| Version | [Android Gradle plugin version](https://developer.android.com/studio/releases/gradle-plugin#updating-gradle) | Gradle version |
141229
|------------|--------------------------------------------------------------------------------------------------------------|------------------------|
142-
| **1.9.0** | 8.6.0 | 8.7+ |
230+
| **1.9.0** | 8.6.0+ | 8.7+ |
143231
| **1.8.0** | 8.5.2<br/>8.4.2<br/>8.3.0-alpha05 - 8.3.2 | 8.6+<br/>8.5+<br/>8.4+ |
144-
| **Note 2** | 8.0 - 8.3.0-alpha04 | n.a. |
232+
| **Note 1** | 8.0 - 8.3.0-alpha04 | n.a. |
145233
| **1.7.1** | 7.4 | 7.5+ |
146234
| **1.6.0** | 7.3 | 7.4+ |
147235
| **1.5.3** | 7.2 | 7.3+ |
148-
| **Note 3** | 7.0 - 7.2.0-alpha05 | n.a. |
236+
| **Note 2** | 7.0 - 7.2.0-alpha05 | n.a. |
149237
| **1.4.0** | 4.2<br/>4.1 | 6.7.1+<br/>6.5+ |
150238
| **1.3.1** | 4.0<br/>3.6 | 6.1.1+<br/>5.6.4+ |
151239
| **1.2.1** | 3.5 | 5.4.1+ |
152240
| **1.1.2** | 3.4 | 5.1.1+ |
153241
| **1.1.1** | 3.3 | 4.10.1+ |
154242
| **1.0.2** | 3.2 | 4.6+ |
155243

156-
<details open>
157-
<summary><b>Note 2: AGP 8.0-8.3.0-alpha04</b></summary>
244+
<details>
245+
<summary><b>Note 1: AGP 8.0-8.3.0-alpha04</b></summary>
158246

159247
*Android Gradle Plugin version 8.0 till 8.3.0-alpha04 suffered from a [bug](https://issuetracker.google.com/u/0/issues/281266702) that made it impossible (by normal means) to get access to non-instrumented class files, this bug lasted for a long time and was only fixed in 8.3.0-alpha05. This means there is no stable working plugin version available for these AGP versions.*
160248
</details>
161249

162250
<details>
163-
<summary><b>Note 3: AGP 7.0-7.2.0-alpha05</b></summary>
251+
<summary><b>Note 2: AGP 7.0-7.2.0-alpha05</b></summary>
164252

165253
*Android Gradle Plugin version 7 till 7.2.0-alpha05 suffered from a [bug](https://issuetracker.google.com/issues/195860510) that caused instrumented coverage in Android library modules to fail, this has only been [fixed](https://github.com/NeoTech-Software/Android-Root-Coverage-Plugin/issues/36#issuecomment-977241070) in Android Gradle Plugin 7.2.0-alpha06. This means there is no stable working plugin version available for these AGP versions.*
166254
</details>
167255

168256
<details>
169-
<summary><b>Note 4: group ID change & Maven Central</b></summary>
257+
<summary><b>Note 3: Versions 1.0.2 to 1.3.0</b></summary>
170258

171-
*Plugin versions below 1.3.1, such as 1.3.0, are only available on the Gradle Plugin Portal (`maven { url "https://plugins.gradle.org/m2/"}`) and not on Maven Central. These versions use the group ID `org.neotech.plugin` and plugin ID `org.neotech.plugin.rootcoverage`!*
259+
*Plugin versions below 1.3.1, such as 1.3.0, are only available on the Gradle Plugin Portal and not on Maven Central. These versions use the group ID `org.neotech.plugin` and plugin ID `org.neotech.plugin.rootcoverage`! For more info see: [Bintray/JCenter shutdown](#4-bintrayjcenter-shutdown).*
172260
</details>
173261

174262
<details>
175-
<summary><b>Note 5: AGP versions before 3.4.0-alpha05</b></summary>
263+
<summary><b>Note 4: AGP versions before 3.4.0-alpha05</b></summary>
176264

177265
*Android Gradle Plugin versions before `3.4.0-alpha05` are affected by a bug that in certain conditions can cause Jacoco instrumentation to fail in combination with inline kotlin methods shared across modules. For more information see: [issue #109771903](https://issuetracker.google.com/issues/109771903) and [issue #110763361](https://issuetracker.google.com/issues/110763361). If your project is affected by this upgrade to an Android Gradle Plugin version of at least `3.4.0-alpha05`.*
178266
</details>
@@ -184,18 +272,25 @@ the Android-Root-Coverage-Plugin has been migrated to Sonatype's Maven Central r
184272
meant that the group ID used by the Android-Root-Coverage-Plugin had to be changed from `org.neotech.plugin` to
185273
`nl.neotech.plugin`. The plugin ID has also changed from `org.neotech.plugin.rootcoverage` to `nl.neotech.plugin.rootcoverage`.
186274

187-
JCenter is supposed to stay available as read-only repository, however it is probably better to migrate to
188-
the Gradle Plugin Portal, since all version of this plugin are also available there:
189-
```groovy
190-
pluginManagement {
191-
repositories {
192-
gradlePluginPortal()
275+
<details>
276+
<summary><strong>More info</strong></summary>
277+
278+
JCenter is supposed to stay available as read-only repository, however it is probably better to
279+
migrate to the Gradle Plugin Portal, as it is the official Gradle repository for plugins, and all
280+
versions of this plugin are available there:
281+
```groovy
282+
pluginManagement {
283+
repositories {
284+
// Add this repository to your build script for plugin resolution, above mavenCentral() or jcenter()
285+
gradlePluginPortal()
286+
}
193287
}
194-
}
195-
```
196-
Version 1.3.0 has been re-released (as 1.3.1) with the new group ID and plugin ID to Maven Central and the
197-
Gradle Plugin Portal. Upcoming versions will also be released to Maven Central and the Gradle Plugin Portal.
198-
Check the [setup](#1-setup) section on how to use this plugin with the updated group ID and plugin ID.
288+
```
289+
Version 1.3.0 has been re-released (as 1.3.1) with the new group ID and plugin ID to Maven Central and the
290+
Gradle Plugin Portal. Upcoming versions will also be released to Maven Central and the Gradle Plugin Portal.
291+
Check the [setup](#1-setup) section on how to use this plugin with the updated group ID and plugin ID.
292+
293+
</details>
199294

200295

201296
# 5. Development

0 commit comments

Comments
 (0)