forked from BottleRocketStudios/Android-Maps-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjacocoRoot.gradle
98 lines (86 loc) · 5.15 KB
/
jacocoRoot.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
94
95
96
97
98
apply plugin: 'jacoco'
def verboseLogging = false
jacoco {
toolVersion = project.jacocoVersion
}
/**
* Creates gradle tasks that generates a comprehensive project Jacoco coverage report based on app/data/domain modules for each project variant (build type + product flavor)
*
* Setup:
* Apply to root build.gradle.kts
* Ex: apply(from = "jacocoRoot.gradle")
*
* To run/view jacoco reports:
*
* 1a. Execute the following gradle task in the Android Studio Gradle Tool Window:
* :android-architecture-demo -> reporting -> testVARIANTCombinedUnitTestCoverage // TODO: TEMPLATE - update with project specific root module name here
* Ex - :android-architecture-demo -> reporting -> testInternalDebugCombinedUnitTestCoverage // TODO: TEMPLATE - update with project specific root module name here
* OR 1b. Execute the following in Terminal from project root dir:
* ./gradlew testVARIANTCombinedUnitTestCoverage
* Ex - ./gradlew testInternalDebugCombinedUnitTestCoverage
* 2. Upon successful completion of the task, open the report located in:
* PROJECT_ROOT_DIR/build/reports/jacoco/testVARIANTCombinedUnitTestCoverage/html/index.html
* Ex - open comprehensive report:
* open build/reports/jacoco/testInternalDebugCombinedUnitTestCoverage/html/index.html
* Ex - open comprehensive report + all submodule reports:
* open build/reports/jacoco/testInternalDebugCombinedUnitTestCoverage/html/index.html app/build/reports/jacoco/testInternalDebugUnitTestCoverage/html/index.html data/build/reports/jacoco/testInternalDebugUnitTestCoverage/html/index.html
*
* Inspiration from https://stackoverflow.com/a/41343883/201939
*/
project.afterEvaluate {
// The root project doesn't have access to the android scope to retrieve build types dynamically. This static list should match the actual build types defined in the :app build.gradle.kts
def buildTypes = ["debug", "release"]
// The root project doesn't have access to the android scope to retrieve product flavors dynamically. This static list should match the actual product flavors defined in the :app build.gradle.kts
def productFlavors = ["internal", "production"]
// 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 rootTaskName = "test${sourceName.capitalize()}CombinedUnitTestCoverage"
def testTaskName = "test${sourceName.capitalize()}UnitTestCoverage"
def appModuleTestTaskName = "app:${testTaskName}"
def dataModuleTestTaskName = "data:${testTaskName}"
def composeModuleTestTaskName = "compose:${testTaskName}"
if (verboseLogging) {
println("[jacocoRoot.gradle] productFlavorName=${productFlavorName}")
println("[jacocoRoot.gradle] buildTypeName=${buildTypeName}")
println("[jacocoRoot.gradle] sourceName=${sourceName}")
println("[jacocoRoot.gradle] rootTaskName '${rootTaskName}'")
println("[jacocoRoot.gradle] testTaskName '${testTaskName}'")
println("[jacocoRoot.gradle] appModuleTestTaskName '${appModuleTestTaskName}'")
println("[jacocoRoot.gradle] dataModuleTestTaskName '${dataModuleTestTaskName}'")
println("[jacocoRoot.gradle] composeModuleTestTaskName '${composeModuleTestTaskName}'")
println("[jacocoRoot.gradle] Creating jacoco task named '${rootTaskName}'")
}
task "${rootTaskName}"(type: JacocoReport, dependsOn: ["${appModuleTestTaskName}", "${dataModuleTestTaskName}", "${composeModuleTestTaskName}"]) {
group = "Reporting"
description = "Generate comprehensive project Jacoco coverage report based on app/data/compose modules"
sourceDirectories.from = (files([
tasks.getByPath("${appModuleTestTaskName}").sourceDirectories,
tasks.getByPath("${dataModuleTestTaskName}").sourceDirectories,
tasks.getByPath("${composeModuleTestTaskName}").sourceDirectories
]))
classDirectories.from = (files([
tasks.getByPath("${appModuleTestTaskName}").classDirectories,
tasks.getByPath("${dataModuleTestTaskName}").classDirectories,
tasks.getByPath("${composeModuleTestTaskName}").classDirectories
]))
executionData.from = (files([
tasks.getByPath("${appModuleTestTaskName}").executionData,
tasks.getByPath("${dataModuleTestTaskName}").executionData,
tasks.getByPath("${composeModuleTestTaskName}").executionData
]))
reports {
xml.required.set(true)
html.required.set(true)
}
}
}
}
}