-
Notifications
You must be signed in to change notification settings - Fork 0
/
jacoco-config.gradle
65 lines (57 loc) · 2.71 KB
/
jacoco-config.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
/**
* 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 = fileTree(
dir: "${project.buildDir}/intermediates/classes/${pathNameWithFlavor}",
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 = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = fileTree(dir: project.projectDir, includes: ["**/*.exec", "**/*.ec"])
reports {
xml.enabled = true
html.enabled = true
}
}
}
}