-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcoverage.gradle
81 lines (73 loc) · 2.5 KB
/
coverage.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
apply plugin: "jacoco"
apply plugin: 'com.github.kt3k.coveralls'
jacoco {
toolVersion = versions.jacoco
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
task('jacocoReports') {
group = "Reporting"
description = "Generate Jacoco coverage reports for all variants"
}
variants().all { variant ->
def variantName = variant.name
def variantCapName = variant.name.capitalize()
if (!variantCapName.contains("Debug")) {
return
}
def variantTask = task(
"jacoco${variantCapName}Report",
type: JacocoReport,
dependsOn: [
"test${variantCapName}UnitTest"
]) {
group = "Reporting"
description = "Generate Jacoco coverage reports for $variantCapName"
reports {
xml.enabled = true // coveralls plugin depends on xml format report
html.enabled = true
}
def fileFilter = [ '**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'**/injectors/**/*.*',
'android/**/*.*',
'androidx/**/*.*',
'com/**/*.*',
'io/**/*.*',
'**/ui/**/*.*'
]
def classTree = fileTree(
dir: variant.javaCompiler.destinationDir,
excludes: fileFilter
) + fileTree(
dir: "$buildDir/tmp/kotlin-classes/$variantName",
excludes: fileFilter
)
sourceDirectories = files([
"src/main/java", "src/main/kotlin",
"src/$variantName/java", "src/$variantName/kotlin"
])
classDirectories = files([classTree])
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/test${variantCapName}UnitTest.exec",
"jacoco/junitPlatformTest${variantCapName}.exec",
"outputs/code-coverage/connected/flavors/**/*coverage.ec"
])
}
jacocoReports.dependsOn variantTask
}
check.dependsOn jacocoReports
def variants() {
if (project.android.hasProperty('libraryVariants')) {
return project.android.libraryVariants
} else {
return project.android.applicationVariants
}
}
coveralls {
jacocoReportPath = "$buildDir/reports/jacoco/jacocoProdDebugReport/jacocoProdDebugReport.xml"
}