-
Notifications
You must be signed in to change notification settings - Fork 31
/
jacoco.gradle
108 lines (86 loc) · 3.67 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
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.4"
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
afterEvaluate {
task jacocoTestReport(type: JacocoReport) {
outputs.cacheIf { true }
Task runTestsTask
group "Reporting"
description "Generate Jacoco coverage reports."
print "configuring jacoco for project: ${project.name}"
if (project.tasks.findByName('testDevelopDebugUnitTest')) {
runTestsTask = project.tasks.findByName('testDevelopDebugUnitTest')
} else {
runTestsTask = project.tasks.findByName('testDebugUnitTest')
}
dependsOn runTestsTask
def outputFileName = "coverage/coverage-${project.name}.xml"
def outputFileNameHtml = "coverage/coverage-${project.name}.html"
def file = new File("coverage/")
if (!file.exists()) file.mkdirs()
reports {
xml.enabled = true
html.enabled = true
html.setDestination(new File(outputFileNameHtml))
xml.setDestination(new File(outputFileName))
}
outputs.upToDateWhen { false }
def javaClasses = []
def kotlinClasses = []
def sourceDirs = []
def execution = []
def fileFilter = ['**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test.*',
'**/*Activity.*',
'**/*Fragment.*',
'**/*Adapter.*',
'**/*Holder.*',
'**/*App.*',
'**/*Application.*',
'**/*Dialog.*',
'**/*Ext.*',
'**/*ViewPager.*',
'**/*Module.*',
'**/*Dependencies.*',
'**/*Router.*',
'**/*Component.*',
'**/*ViewModelFactory.*',
'**/*Api.*',
'**/*Dao.*',
'android/**/*.*',
'**/com/google/protobuf/**/*.*',
'**/com/google/api/*.*',
'**/data/db/dao/*.*',
'**/android/databinding/layouts/*.*',
'**/androidx/databinding/library/baseAdapters/*.*',
'**/*Activity.*',
'**/*Fragment.*',
'**/di/**',
'**/view/**',
]
javaClasses << fileTree(dir: "$buildDir/intermediates/javac/debug", excludes: fileFilter)
kotlinClasses << fileTree(dir: "$buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
sourceDirs << fileTree(dir: "$projectDir/src/main/java", excludes: fileFilter)
execution << fileTree(dir: buildDir,
includes: ["jacoco/${runTestsTask.name}.exec",
'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'])
executionData.setFrom(files(execution))
sourceDirectories.setFrom(files([sourceDirs]))
classDirectories.setFrom(files([javaClasses, kotlinClasses]))
doFirst {
print "generating jacoco report for project: ${project.name} \n"
print "sourceDirs = " + sourceDirs + '\n'
print "execution = " + execution + '\n'
print "classDirectoriesJava = " + javaClasses + '\n'
print "classDirectoriesKT = " + kotlinClasses + '\n'
}
}
}