-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
143 lines (128 loc) · 4.76 KB
/
build.gradle.kts
File metadata and controls
143 lines (128 loc) · 4.76 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Top-level build file where you can add configuration options common to all sub-projects/modules.
group = "org.hisp.dhis"
version = libs.versions.vName.get()
buildscript {
dependencies {
classpath(libs.gradlePlugin)
classpath(libs.kotlinPlugin)
classpath(libs.jacoco)
classpath(libs.kotlinSerialization)
}
}
plugins {
alias(libs.plugins.ktlint)
alias(libs.plugins.sonarqube)
alias(libs.plugins.compose) apply false
alias(libs.plugins.kotlin.compose.compiler) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.cyclonedx)
}
// Variables to hold aggregated test results
var totalTestsRun: Long = 0
var totalTestsPassed: Long = 0
var totalTestsFailed: Long = 0
var totalTestsSkipped: Long = 0
var totalModules: MutableList<String> = mutableListOf()
var failedTests: MutableList<String> = mutableListOf()
sonarqube {
properties {
val branch = System.getenv("GIT_BRANCH")
val targetBranch = System.getenv("GIT_BRANCH_DEST")
val pullRequestId = System.getenv("PULL_REQUEST")
property("sonar.projectKey", "dhis2_dhis2-android-capture-app")
property("sonar.organization", "dhis2")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.projectName", "android capture app")
if (pullRequestId == null) {
property("sonar.branch.name", branch)
} else {
property("sonar.pullrequest.base", targetBranch)
property("sonar.pullrequest.branch", branch)
property("sonar.pullrequest.key", pullRequestId)
}
}
}
allprojects {
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor(10, TimeUnit.MINUTES)
cacheChangingModulesFor(0, TimeUnit.SECONDS)
eachDependency {
if (requested.group == "org.jacoco")
useVersion("0.8.10")
}
}
}
apply(plugin = "org.jlleitschuh.gradle.ktlint")
gradle.projectsEvaluated {
tasks.withType<JavaCompile> {
options.compilerArgs.addAll(
listOf(
"-Xmaxerrs",
"1000"
)
)
}
}
ktlint {
version.set("1.7.1")
debug.set(true)
verbose.set(true)
android.set(true)
outputToConsole.set(true)
enableExperimentalRules.set(true)
filter {
excludes.add("**/*.kts")
exclude { element -> element.file.path.contains("androidTest") }
exclude { element -> element.file.path.contains("generated") }
exclude { element -> element.file.path.contains("dhis2-android-sdk") }
}
}
tasks.withType<AbstractTestTask> {
afterSuite(
KotlinClosure2({ desc: TestDescriptor, result: TestResult ->
if (result.resultType == TestResult.ResultType.FAILURE) {
synchronized(rootProject) {
val testName = desc.className + "." + desc.name
failedTests.add(testName)
}
}
if (desc.parent == null) {
synchronized(rootProject) {
totalModules.add(project.name)
totalTestsRun += result.testCount
totalTestsPassed += result.successfulTestCount
totalTestsFailed += result.failedTestCount
totalTestsSkipped += result.skippedTestCount
}
}
})
)
}
}
// Initialize extra properties on the root project for storing totals
rootProject.ext.set("totalTestsRun", 0L)
rootProject.ext.set("totalTestsPassed", 0L)
rootProject.ext.set("totalTestsFailed", 0L)
rootProject.ext.set("totalTestsSkipped", 0L)
rootProject.ext.set("totalModules", mutableListOf<String>())
gradle.addBuildListener(object : BuildAdapter() {
override fun buildFinished(result: BuildResult) {
println("================================================")
println(" AGGREGATED TEST RESULTS")
println("================================================")
println(" Modules: ${totalModules.joinToString(", ")}")
println(" Total Tests Run: $totalTestsRun")
println(" Total Passed: $totalTestsPassed")
println(" Total Failed: $totalTestsFailed")
println(" Total Skipped: $totalTestsSkipped")
println("================================================")
if (totalTestsFailed > 0) {
println(" Failed Tests:")
failedTests.forEach {
println(" *** $it")
}
println("================================================")
}
}
})