-
Notifications
You must be signed in to change notification settings - Fork 6
/
jacoco.gradle
53 lines (49 loc) · 2.27 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
apply plugin: 'jacoco'
jacoco {
// Gradle 6.7.1 ships with JaCoCo 0.8.5 (October 2019) but we wanted to use the more recent version.
// We've since upgraded to Gradle 7, but still manually pinning this.
toolVersion = '0.8.8' // April 2022
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
// Fixes failing tests when running on JDK 9 or above https://github.com/gradle/gradle/issues/5184#issuecomment-457865951
jacoco.excludes = ['jdk.internal.*']
}
project.afterEvaluate {
// Grab all build types and product flavors
def buildTypes = android.buildTypes.collect { type ->
type.name
}
def productFlavors = android.productFlavors.collect { flavor ->
flavor.name
}
// When no product flavors defined, use empty
if (!productFlavors) productFlavors.add('')
productFlavors.each { productFlavorName ->
buildTypes.each { buildTypeName ->
def sourceName
if (!productFlavorName) {
sourceName = "${buildTypeName}"
} else {
sourceName = "${productFlavorName}${buildTypeName.capitalize()}"
}
def testTaskName = "test${sourceName.capitalize()}UnitTest"
// Create coverage task of form 'testFlavorTypeCoverage' depending on 'testFlavorTypeUnitTest'
task "${testTaskName}Coverage"(type: JacocoReport, dependsOn: "$testTaskName") {
group = "Reporting"
description = "Generate Jacoco coverage reports for the ${sourceName.capitalize()} build."
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/$productFlavorName/$buildTypeName")
def kotlinDebugTree = fileTree(dir: "${buildDir}/tmp/kotlin-classes/$sourceName")
classDirectories.from = files([debugTree], [kotlinDebugTree])
def coverageSourceDirs = [
'src/main/java',
"src/$productFlavorName/java",
"src/$buildTypeName/java"
]
additionalSourceDirs.from = files(coverageSourceDirs)
sourceDirectories.from = files(coverageSourceDirs)
executionData.from = files("${project.buildDir}/jacoco/${testTaskName}.exec")
}
}
}
}