-
Notifications
You must be signed in to change notification settings - Fork 16
/
jacoco.gradle
116 lines (100 loc) · 4.66 KB
/
jacoco.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
apply plugin: 'jacoco'
// for the flow flavour for example do ./gradlew testFlowDebugUnitTestCoverage to generate a report
jacoco {
toolVersion = "$jacocoVersion"
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
project.afterEvaluate {
(android.hasProperty('applicationVariants')
? android.'applicationVariants'
: android.'libraryVariants').all { variant ->
def variantName = variant.name
def unitTestTask = "test${variantName.capitalize()}UnitTest"
def uiTestCoverageTask = "create${variantName.capitalize()}CoverageReport"
tasks.create(name: "${unitTestTask}Coverage", type: JacocoReport, dependsOn: [
"$unitTestTask",
"$uiTestCoverageTask",
":data:testDebugUnitTest",
":database:testDebugUnitTest",
":domain:testDebugUnitTest",
":offlinemaps:testDebugUnitTest",
":uicomponents:testDebugUnitTest",
":walkthrough:testDebugUnitTest",
]) {
group = "Reporting"
description = "Generate Jacoco coverage reports for the ${variantName.capitalize()} build"
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
def excludedFiles = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
'**/*$ViewInjector*.*',
'**/*Component*.*',
'**/*$Lambda$*.*',
'**/*Companion*.*',
'**/*Module.*',
'**/*Dagger*.*',
'**/*MembersInjector*.*',
'**/*_Factory*.*',
'**/*_Provide*Factory*.*'
]
classDirectories.setFrom(files([
fileTree(dir: "${buildDir}/tmp/kotlin-classes/${variantName}", excludes: excludedFiles),
fileTree(dir: "${buildDir}/intermediates/javac/${variantName}", excludes: excludedFiles),
fileTree(dir: kotlinClassesPath("data"), excludes: excludedFiles),
fileTree(dir: javaClassesPath("data"), excludes: excludedFiles),
fileTree(dir: kotlinClassesPath("domain"), excludes: excludedFiles),
fileTree(dir: javaClassesPath("domain"), excludes: excludedFiles),
fileTree(dir: kotlinClassesPath("database"), excludes: excludedFiles),
fileTree(dir: javaClassesPath("database"), excludes: excludedFiles),
fileTree(dir: kotlinClassesPath("offlinemaps"), excludes: excludedFiles),
fileTree(dir: javaClassesPath("offlinemaps"), excludes: excludedFiles),
fileTree(dir: kotlinClassesPath("uicomponents"), excludes: excludedFiles),
fileTree(dir: javaClassesPath("uicomponents"), excludes: excludedFiles),
fileTree(dir: kotlinClassesPath("walkthrough"), excludes: excludedFiles),
fileTree(dir: javaClassesPath("walkthrough"), excludes: excludedFiles),
]))
def coverageSourceDirs = [
sourcesPath("app"),
sourcesPath("data"),
sourcesPath("domain"),
sourcesPath("database"),
sourcesPath("offlinemaps"),
sourcesPath("uicomponents"),
sourcesPath("walkthrough"),
]
additionalSourceDirs.setFrom(files(coverageSourceDirs))
sourceDirectories.setFrom(files(coverageSourceDirs))
def uiTestsData = fileTree(dir: "${buildDir}/outputs/code_coverage/${variantName}AndroidTest/connected/", includes: ["**/*.ec"])
executionData(files([
"$project.buildDir/jacoco/${unitTestTask}.exec",
uiTestsData,
reportPath("data"),
reportPath("domain"),
reportPath("database"),
]))
}
}
}
private GString reportPath(module) {
"$project.rootDir/" + module + "/build/jacoco/testDebugUnitTest.exec"
}
private GString sourcesPath(module) {
"$project.rootDir/" + module + "/src/main/java"
}
private GString javaClassesPath(module) {
"$project.rootDir/" + module + "/build/intermediates/javac/debug"
}
private GString kotlinClassesPath(module) {
"$project.rootDir/" + module + "/build/tmp/kotlin-classes/debug"
}