-
Notifications
You must be signed in to change notification settings - Fork 7
/
jacoco.gradle
105 lines (94 loc) · 3.34 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
ext.enableJacoco = { Project project, String variant ->
project.plugins.apply('jacoco')
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
final capVariant = variant.capitalize()
StringBuilder folderSb = new StringBuilder(variant.length() + 1)
for (int i = 0; i < variant.length(); i++) {
char c = variant.charAt(i)
if (Character.isUpperCase(c)) {
folderSb.append('/')
folderSb.append(Character.toLowerCase(c))
} else {
folderSb.append(c)
}
}
project.android.testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
project.jacoco {
toolVersion = '0.8.2'
}
project.android {
buildTypes {
debug {
testCoverageEnabled = false //https://github.com/objectbox/objectbox-java/issues/179
}
}
}
project.tasks.create(
name: 'jacocoTestReport',
type: JacocoReport,
dependsOn: ["test${capVariant}UnitTest", "create${capVariant}CoverageReport"]
) {
def buildDir = project.buildDir
def coverageSourceDirs = [
"src/main/kotlin"
]
def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Module.*', // Modules for Dagger.
'**/*Dagger*.*', // Dagger auto-generated code.
'**/*MembersInjector*.*', // Dagger auto-generated code.
'**/*_Provide*Factory*.*',// Dagger auto-generated code.
'**/*ObjectBox*.*', // ObjectBox auto-generated code.
'**/*$Lambda$*.*', // Jacoco can not handle several "$"
'**/*_Factory.*', //Dagger auto-generated code
'**/*$*$*.*', // Anonymous classes generated by kotlin
//add libraries
'android/**/*.*',
'com/**/*.*',
'uk/**/*.*',
'io/**/*.*',
'androidTest/**/*.*',
'test/**/*.*',
'**/di/**/*.*',
'**/model/**/*.*',
'**/mock/**/*.*',
'**/event/**/*.*',
'**/**_ViewBinding**',
'**/*EventType.*',
'**/di/**',
'**/**Mocked'
]
def kotlinClasses = fileTree(
dir: "$buildDir/tmp/kotlin-classes/$variant",
excludes: fileFilter
)
group = "Reporting"
description = "Generate Jacoco coverage reports for the ${project.name} with the " +
"$variant variant."
classDirectories = files([ kotlinClasses ])
additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
//executionData = files("${project.buildDir}/jacoco/test${capVariant}UnitTest.exec")
executionData = fileTree(dir: "${project.buildDir}", includes: [
"jacoco/test${capVariant}UnitTest.exec",
"output/code-coverage/connected/*.ec"
])
reports {
xml.enabled = true
html.enabled = true
}
}
}