@@ -11,7 +11,7 @@ buildscript {
11
11
ui_library_version_code = getVersionCode()
12
12
13
13
kotlin_version = ' 1.7.20'
14
- jacoco_version = ' 0.8.7 '
14
+ jacoco_version = ' 0.8.8 '
15
15
junit_version = ' 4.13.2'
16
16
17
17
androidx_activity_ktx_version = ' 1.4.0'
@@ -83,6 +83,12 @@ plugins {
83
83
}
84
84
85
85
allprojects {
86
+ apply plugin : ' jacoco'
87
+
88
+ jacoco {
89
+ toolVersion = " $jacoco_version "
90
+ }
91
+
86
92
Properties localProps = new Properties ()
87
93
if (project. rootProject. file(' local.properties' ). canRead()) {
88
94
localProps. load(project. rootProject. file(' local.properties' ). newDataInputStream())
@@ -116,6 +122,56 @@ subprojects {
116
122
}
117
123
}
118
124
119
- task clean (type : Delete ) {
125
+ tasks. register(" combinedCoverageReport" , JacocoReport ) {
126
+ group = " Reporting"
127
+ description = " Generate a Jacoco coverage report for debug unit tests in all subprojects"
128
+
129
+ def excludeFiles = [
130
+ ' **/R.class' ,
131
+ ' **/R$*.class' ,
132
+ ' **/*$ViewInjector*.*' ,
133
+ ' **/*$ViewBinder*.*' ,
134
+ ' **/BuildConfig.*' ,
135
+ ' **/Manifest*.*'
136
+ ]
137
+
138
+ def coverageSourceDirs = subprojects. collect {
139
+ " $it . projectDir /src/main/java"
140
+ }
141
+
142
+ def javaClasses = subprojects. collect {
143
+ " $it . buildDir /intermediates/javac/debug"
144
+ }. collect { path ->
145
+ fileTree(dir : path, excludes : excludeFiles)
146
+ }
147
+
148
+ def kc = subprojects. collect {
149
+ " $it . buildDir /tmp/kotlin-classes/debug"
150
+ }
151
+
152
+ def kotlinClasses = kc. collect { path ->
153
+ fileTree(dir : path, excludes : excludeFiles)
154
+ }
155
+
156
+ classDirectories. setFrom(files([javaClasses], [kotlinClasses]))
157
+ sourceDirectories. setFrom(files(coverageSourceDirs))
158
+
159
+ def coverageExecPath = " outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec"
160
+ executionData. setFrom(files(subprojects. findAll { proj ->
161
+ def path = " $proj . buildDir /$coverageExecPath "
162
+ (new File (path)). exists()
163
+ }. collect { proj ->
164
+ " $proj . buildDir /$coverageExecPath "
165
+ }))
166
+
167
+ reports {
168
+ xml. required = true
169
+ html. required = true
170
+ html. outputLocation = layout. buildDirectory. dir(" reports/coverage/test/debug" )
171
+ xml. outputLocation = layout. buildDirectory. file(" reports/coverage/test/debug/report.xml" )
172
+ }
173
+ }
174
+
175
+ tasks. register(" clean" , Delete ) {
120
176
delete rootProject. buildDir
121
177
}
0 commit comments