-
Notifications
You must be signed in to change notification settings - Fork 0
/
jacoco.gradle
93 lines (90 loc) · 3.68 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
project.afterEvaluate {
def excludes = [
'**/R.class',
'**/R$*.class',
'**/*BR*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*\$ViewInjector*.*',
'**/*\$ViewBinder*.*',
'**/*\$Lambda$*.*', // Jacoco can not handle several '$' in class name.
'**/*Module.*', // Modules for Dagger.
'**/*Dagger*.*', // Dagger auto-generated code.
'**/*Hilt*.*',
'**/*hilt_*/*.*',
'**/*MembersInjector*.*', // Dagger auto-generated code.
'**/*_Provide*Factory*.*',
'**/*_AssistedFactory*.*',
'**/*_Impl*.*',
'**/*_Factory.*', //Dagger auto-generated code
'**/*Factory.*', //Dagger auto-generated code
'**/*$*$*.*', // Anonymous classes generated by kotlin
//add libraries
'android/**/*.*',
// 'com/**/*.*',
'uk/**/*.*',
'io/**/*.*',
//remove what we don't test
'androidTest/**/*.*',
'test/**/*.*',
'**/injector/**/*.*',
'**/model/**/*.*',
'**/mock/**/*.*',
'**/event/**/*.*',
'**/**_ViewBinding**',
'**/**Directions**',
'**/**Args**',
'**/**DaoImp**',
'**/**_Factory**',
'**/*EventType.*',
'**/**Mocked',
'**/*DataBind*.*',
'**/databinding/*',
'**/di/*',
'**/util/*',
'**/*Activity*.*',
'**/Base*.*',
'**/base/*.*',
'**/*Listener*.*'
]
android.applicationVariants.forEach { variant ->
def variantName = variant.name
def compiler = variant.javaCompileProvider.get()
def testTaskName = "test${variantName.capitalize()}UnitTest"
def coverageTaskName = "${testTaskName}Coverage"
def coverageVerificationTaskName = "${testTaskName}CoverageVerification"
def javaClasses = project.fileTree(dir: compiler.destinationDir, excludes: excludes)
def kotlinClasses = project.fileTree(
dir: "${project.buildDir}/tmp/kotlin-classes/${variantName}",
excludes: excludes
)
def mainSrc = "${project.projectDir}/src/main/java/"
def debug = "${project.projectDir}/src/debug/java/"
def sources = [mainSrc, debug]
project.tasks.create(coverageTaskName, JacocoReport) {
group = "Reporting"
description =
"Generate Jacoco coverage reports for the ${variantName.capitalize()} build."
executionData.setFrom(project.files("${project.buildDir}/jacoco/${testTaskName}.exec"))
it.dependsOn(project.tasks.getByName(testTaskName))
it.mustRunAfter(project.tasks.getByName(testTaskName))
}
project.tasks.create(coverageVerificationTaskName, JacocoCoverageVerification) {
group = "Reporting"
description = "Jacoco coverage verification for the ${variantName.capitalize()} build."
sourceDirectories.setFrom(project.files(sources))
classDirectories.setFrom(project.files(javaClasses, kotlinClasses))
executionData.setFrom(project.files("${project.buildDir}/jacoco/${testTaskName}.exec"))
violationRules {
it.failOnViolation(true)
it.rule {
limit {
minimum = "0.18".toBigDecimal()
}
}
}
it.dependsOn(project.tasks.getByName(coverageTaskName))
it.mustRunAfter(project.tasks.getByName(coverageTaskName))
}
}
}