-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflavored_jacoco.gradle
More file actions
71 lines (62 loc) · 3.02 KB
/
flavored_jacoco.gradle
File metadata and controls
71 lines (62 loc) · 3.02 KB
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
/**
* Apply it in the module build.script.
*/
apply plugin: 'jacoco'
project.afterEvaluate {
def flavors = android.productFlavors.collect { flavor -> flavor.name }
// If there are no flavors defined, add empty flavor.
if (!flavors) flavors.add('')
def buildType = "Debug"
flavors.each { productFlavorName ->
def taskNameWithFlavor, pathNameWithFlavor
if (!productFlavorName) {
//empty flavors
taskNameWithFlavor = pathNameWithFlavor = "${buildType}"
} else {
taskNameWithFlavor = "${productFlavorName}${buildType}"
pathNameWithFlavor = "${productFlavorName}/${buildType}"
}
def unitTestsTaskName = "test${taskNameWithFlavor.capitalize()}UnitTest"
def uiTestsTaskName = "connected${taskNameWithFlavor.capitalize()}AndroidTest"
// Create coverage task ex: 'jacocoTestReport<Flavor>' depending on
// 'testFlavorDebugUnitTest - unit tests' & connectedFlavorDebugAndroidTest - integration tests.
task "jacocoTestReport${productFlavorName.capitalize()}"(type: JacocoReport, dependsOn: [unitTestsTaskName, uiTestsTaskName]) {
group = "Reporting"
description = "Generate Jacoco coverage reports on the ${taskNameWithFlavor.capitalize()} build."
classDirectories.from(fileTree(
// dir: "${project.buildDir}/intermediates/classes/${pathNameWithFlavor}",
dir: "$project.buildDir/intermediates/javac/debug",
excludes: ['**/R.class',
'**/R$*.class',
'**/BuildConfig.class',
'**/Manifest.class',
'**/Manifest$*.class',
'**/*$InjectAdapter.class',
'**/*$ModuleAdapter.class',
'**/*$ViewInjector*.class',
'**/*_MembersInjector.class',
'**/Dagger*Component.class',
'**/Dagger*Component$Builder.class',
'**/*Module_*Factory.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*'
])
)
def coverageSourceDirs = [
"src/main/java",
"src/$productFlavorName/java",
"src/$buildType/java"
]
additionalSourceDirs.from(files(coverageSourceDirs))
sourceDirectories.from(files(coverageSourceDirs))
// executionData.from(fileTree(dir: project.projectDir, includes: ["**/*.exec", "**/*.ec"]))
executionData.from(fileTree(dir: project.buildDir, includes: [
"jacoco/${unitTestsTaskName}.exec", "outputs/code_coverage/${unitTestsTaskName}/connected/**/*.ec"
]))
reports {
xml.enabled = true
html.enabled = true
}
}
}
}