Skip to content

Commit 457b03b

Browse files
Update file filters (commons-app#4640)
1 parent 18b3e50 commit 457b03b

File tree

1 file changed

+93
-49
lines changed

1 file changed

+93
-49
lines changed

jacoco.gradle

+93-49
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,102 @@ jacoco {
44
toolVersion = "0.8.7"
55
}
66

7-
android {
8-
testOptions {
9-
unitTests.all {
10-
jacoco {
11-
includeNoLocationClasses = true
12-
}
13-
}
14-
}
7+
tasks.withType(Test) {
8+
jacoco.includeNoLocationClasses = true
9+
jacoco.excludes = ['jdk.internal.*']
10+
// see related issue https://github.com/gradle/gradle/issues/5184#issuecomment-457865951
1511
}
1612

1713
project.afterEvaluate {
1814

19-
android.applicationVariants.all { variant ->
20-
def name = variant.name
21-
def testTaskName = "test${name.capitalize()}UnitTest"
22-
23-
tasks.create(name: "${testTaskName}Coverage", type: JacocoReport, dependsOn: "$testTaskName") {
24-
group = "Reporting"
25-
description = "Generate Jacoco coverage reports for the ${name.capitalize()} build."
26-
27-
def fileFilter = ['**/R.class',
28-
'**/R$*.class',
29-
'**/*$ViewInjector*.*',
30-
'**/*$ViewBinder*.*',
31-
'**/BuildConfig.*',
32-
'**/Manifest*.*',
33-
'**/*Test*.*',
34-
'android/**/*.*']
35-
36-
//java compiled classes
37-
def javaTree = fileTree(
38-
dir: "${buildDir}/intermediates/classes/${name}",
39-
excludes: fileFilter
40-
)
41-
//kotlin compiled classes
42-
def kotlinTree = fileTree(
43-
dir: "${buildDir}/tmp/kotlin-classes/${name}",
44-
excludes: fileFilter
45-
)
46-
def mainSrc = "${project.projectDir}/src/main/java"
47-
48-
sourceDirectories.setFrom(files([mainSrc]))
49-
classDirectories.setFrom(files([javaTree, kotlinTree]))
50-
executionData.setFrom(fileTree(dir: "${buildDir}", includes: [
51-
"jacoco/${testTaskName}.exec",
52-
"outputs/code-coverage/connected/*coverage.ec"
53-
]))
54-
55-
reports {
56-
xml.enabled = true
57-
html.enabled = true
15+
(android.hasProperty('applicationVariants')
16+
? android.'applicationVariants'
17+
: android.'libraryVariants')
18+
.all { variant ->
19+
def variantName = variant.name
20+
def unitTestTask = "test${variantName.capitalize()}UnitTest"
21+
22+
tasks.create(name: "${unitTestTask}Coverage", type: JacocoReport, dependsOn: [
23+
"$unitTestTask"
24+
]) {
25+
group = "Reporting"
26+
description = "Generate Jacoco coverage reports for the ${variantName.capitalize()} build"
27+
28+
reports {
29+
html.enabled = true
30+
xml.enabled = true
31+
}
32+
33+
def excludes = [
34+
// data binding
35+
'android/databinding/**/*.class',
36+
'**/android/databinding/*Binding.class',
37+
'**/android/databinding/*',
38+
'**/androidx/databinding/*',
39+
'**/BR.*',
40+
// android
41+
'**/R.class',
42+
'**/R$*.class',
43+
'**/BuildConfig.*',
44+
'**/Manifest*.*',
45+
'**/*Test*.*',
46+
'android/**/*.*',
47+
// butterKnife
48+
'**/*$ViewInjector*.*',
49+
'**/*$ViewBinder*.*',
50+
'**/*ViewBinding*.*',
51+
// dagger
52+
'**/*_MembersInjector.class',
53+
'**/Dagger*Component.class',
54+
'**/Dagger*Component$Builder.class',
55+
'**/*Module_*Factory.class',
56+
'**/di/module/*',
57+
'**/*_Factory*.*',
58+
'**/*Module*.*',
59+
'**/*Dagger*.*',
60+
'**/*Hilt*.*',
61+
// kotlin
62+
'**/*MapperImpl*.*',
63+
'**/*$ViewInjector*.*',
64+
'**/*$ViewBinder*.*',
65+
'**/BuildConfig.*',
66+
'**/*Component*.*',
67+
'**/*BR*.*',
68+
'**/Manifest*.*',
69+
'**/*$Lambda$*.*',
70+
'**/*Companion*.*',
71+
'**/*Module*.*',
72+
'**/*Dagger*.*',
73+
'**/*Hilt*.*',
74+
'**/*MembersInjector*.*',
75+
'**/*_MembersInjector.class',
76+
'**/*_Factory*.*',
77+
'**/*_Provide*Factory*.*',
78+
'**/*Extensions*.*',
79+
// sealed and data classes
80+
'**/*$Result.*',
81+
'**/*$Result$*.*'
82+
]
83+
84+
def javaClasses = fileTree(dir: variant.javaCompileProvider.get().destinationDir,
85+
excludes: excludes)
86+
def kotlinClasses = fileTree(dir: "${buildDir}/tmp/kotlin-classes/${variantName}",
87+
excludes: excludes)
88+
89+
classDirectories.setFrom(files([
90+
javaClasses,
91+
kotlinClasses
92+
]))
93+
94+
def variantSourceSets = variant.sourceSets.java.srcDirs.collect { it.path }.flatten()
95+
sourceDirectories.setFrom(project.files(variantSourceSets))
96+
97+
executionData(files([
98+
"$project.buildDir/jacoco/${unitTestTask}.exec"
99+
]))
100+
}
101+
58102
}
59-
}
60-
}
103+
104+
61105
}

0 commit comments

Comments
 (0)