You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**A Gradle plugin for easy generation of combined code coverage reports for Android projects with multiple modules.**
3
+
Android Projects that make use of the Gradle build system by default come with easy methods to generate code coverage reports. Unfortently by default code coverage is generated seperatly per module, this means each modules takes into account it's own sources and tests, which is in terms of domain seperation fine. Howerver it is very common to find multi-module Android project where only one module has instrumented tests, or full-fledged UI tests using Espresso. This plugin comes in handy for those projects. It generates code coverage reports using Jacoco taking into account all the modules and tests at once.
4
+
5
+
- Supports both Android app and library modules (`com.android.application` & `com.android.library`).
6
+
- Supports different build variants per module within the same report.
7
+
- Supports custom filters.
8
+
9
+
# Download
10
+
The plugin is not yet available on Maven Central, so currently it is needed to add the following repository to your top-level gradle file:
11
+
12
+
**Step 1:**
13
+
```
14
+
// Step 3: Apply the plugin to the top-level gradle file
15
+
apply plugin: 'org.neotech.plugin.rootcoverage'
16
+
17
+
buildscript {
18
+
repositories {
19
+
// Step 1: add the repository
20
+
// This plugin is not yet available on Maven Central, so currently it is needed to add the following repository:
Currently only modules with the plugin type `com.android.application` or `com.android.library` are taken into account when generating the root code coverage report, besides this any module that does not have `testCoverageEnabled true` for the default build variant (`debug`) will be skipped::
34
+
35
+
You can add a module by enableing `testCoverageEnabled`:
36
+
```
37
+
android {
38
+
buildTypes {
39
+
debug {
40
+
testCoverageEnabled true
41
+
}
42
+
}
43
+
}
44
+
```
45
+
46
+
The Android-Root-Coverage-Plugin generates a special Gradle task `:rootCodeCoverageReport` that when executed generates a Jacoco code coverage report. You can either run this task directly from Android Studio using the Gradle Tool Window (see: https://www.jetbrains.com/help/idea/jetgradle-tool-window.html) or from the terminal.
47
+
48
+
-**Gradle Tool Window:** You can find the task under: `Tasks > reporting > rootCodeCoverageReport`, double click to execute it.
49
+
-**Terminal:** Execute the task using `gradlew rootCodeCoverageReport`.
50
+
51
+
# Configuration
52
+
By default the plugin generates code coverage reports using the build variant `debug` for every module. However in some cases different build variants per module might be required, especially if there is no `debug` build variant available. In those cases you can configure custom build variants for specific modules:
53
+
54
+
```
55
+
rootCoverage {
56
+
// The default build variant for every module
57
+
buildVariant "debug"
58
+
// Overrides the default build variant for specific modules.
} ?:throwGradleException("Build variant `$buildVariant` required for module `${project.name}` does not exist! Make sure to use a proper build variant configuration using rootCoverage.buildVariant and rootCoverage.buildVariantOverrides!")
// Configure the root task with sub-tasks for the sub-projects.
77
106
project.subprojects.forEach {
78
107
it.afterEvaluate { subProject ->
79
108
createCoverageTaskForSubProject(subProject, task)
@@ -94,43 +123,41 @@ class RootCoveragePlugin: Plugin<Project> {
94
123
return
95
124
}
96
125
97
-
/* if (subProject.plugins.withType(JacocoPlugin::class.java).isEmpty()) {
98
-
subProject.logger.warn("Jacoco plugin not applied to project: '${subProject.name}'! RootCoveragePlugin automatically applied it but you should do this manually: ${subProject.buildFile}")
// Get the exact required build variant for the current subproject.
106
-
val buildVariant = getBuildVariantFor(subProject)
107
-
when(extension) {
108
-
isLibraryExtension-> {
109
-
extension.libraryVariants.all { variant ->
110
-
if (variant.buildType.isTestCoverageEnabled && variant.name.capitalize() == buildVariant.capitalize()) {
111
-
if (subProject.plugins.withType(JacocoPlugin::class.java).isEmpty()) {
112
-
subProject.logger.warn("Jacoco plugin not applied to project: '${subProject.name}'! RootCoveragePlugin automatically applied it but you should do this manually: ${subProject.buildFile}")
if (variant.buildType.isTestCoverageEnabled && variant.name.capitalize() == buildVariant.capitalize()) {
136
+
if (subProject.plugins.withType(JacocoPlugin::class.java).isEmpty()) {
137
+
subProject.logger.warn("Jacoco plugin not applied to project: '${subProject.name}'! RootCoveragePlugin automatically applied it but you should do this manually: ${subProject.buildFile}")
if (variant.buildType.isTestCoverageEnabled && variant.name.capitalize() == buildVariant.capitalize()) {
123
-
if (subProject.plugins.withType(JacocoPlugin::class.java).isEmpty()) {
124
-
subProject.logger.warn("Jacoco plugin not applied to project: '${subProject.name}'! RootCoveragePlugin automatically applied it but you should do this manually: ${subProject.buildFile}")
if (variant.buildType.isTestCoverageEnabled && variant.name.capitalize() == buildVariant.capitalize()) {
151
+
if (subProject.plugins.withType(JacocoPlugin::class.java).isEmpty()) {
152
+
subProject.logger.warn("Jacoco plugin not applied to project: '${subProject.name}'! RootCoveragePlugin automatically applied it but you should do this manually: ${subProject.buildFile}")
0 commit comments