-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
271 lines (240 loc) · 9.14 KB
/
build.gradle.kts
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import io.gitlab.arturbosch.detekt.Detekt
import org.springframework.boot.gradle.tasks.bundling.BootJar
import java.net.URI
import java.time.Duration
group = "com.swisscom.health.des.cdr"
version = "3.2.2-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
val awaitilityVersion: String by project
val jacocoVersion: String by project
val kacheVersion: String by project
val kfsWatchVersion: String by project
val kotlinCoroutinesVersion: String by project
val kotlinLoggingVersion: String by project
val logstashEncoderVersion: String by project
val micrometerTracingVersion: String by project
val mockkVersion: String by project
val msal4jVersion: String by project
val springCloudVersion: String by project
val springMockkVersion: String by project
val jvmVersion: String by project
val outputDir: Provider<Directory> = layout.buildDirectory.dir(".")
plugins {
id("com.avast.gradle.docker-compose") version "0.17.8"
id("org.springframework.boot")
id("io.spring.dependency-management")
id("io.gitlab.arturbosch.detekt")
jacoco
application
kotlin("jvm")
kotlin("plugin.spring")
// https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.kotlin.configuration-properties
// KAPT is end of life, but KSP is not supported yet: https://github.com/spring-projects/spring-boot/issues/28046
kotlin("kapt")
`maven-publish`
idea
}
idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}
application {
mainClass = "com.swisscom.health.des.cdr.client.CdrClientApplicationKt"
applicationDefaultJvmArgs = listOf("-Dspring.profiles.active=client,customer")
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}")
}
// https://github.com/detekt/detekt/issues/6198#issuecomment-2265183695
configurations.matching { it.name == "detekt" }.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.kotlin") {
useVersion(io.gitlab.arturbosch.detekt.getSupportedKotlinVersion())
}
}
}
}
dependencies {
implementation("com.mayakapps.kache:kache:$kacheVersion")
implementation("com.microsoft.azure:msal4j:$msal4jVersion")
implementation("com.squareup.okhttp3:okhttp")
implementation("io.github.irgaly.kfswatch:kfswatch:$kfsWatchVersion")
implementation("io.github.oshai:kotlin-logging:$kotlinLoggingVersion")
implementation("io.micrometer:micrometer-tracing:$micrometerTracingVersion")
implementation("io.micrometer:micrometer-tracing-bridge-otel:$micrometerTracingVersion")
implementation("net.logstash.logback:logstash-logback-encoder:$logstashEncoderVersion")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinCoroutinesVersion") // to enable @Scheduled on Kotlin suspending functions
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.retry:spring-retry")
kapt("org.springframework.boot:spring-boot-configuration-processor")
testImplementation("org.jacoco:org.jacoco.core:${jacocoVersion}")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test")
testImplementation("com.squareup.okhttp3:mockwebserver") {
// Unfortunately we cannot exclude JUnit 4 as MockWebServer implements interfaces from that version
// exclude(group = "junit", config = "junit")
}
testImplementation("io.mockk:mockk:${mockkVersion}") {
exclude(group = "junit", module = "junit")
}
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("io.micrometer:micrometer-tracing-test")
testImplementation("com.ninja-squad:springmockk:${springMockkVersion}")
testImplementation("org.awaitility:awaitility:${awaitilityVersion}")
}
springBoot {
buildInfo()
}
repositories {
mavenCentral()
}
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(jvmVersion.toInt()))
}
compilerOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}
tasks.test {
useJUnitPlatform {
excludeTags(Constants.INTEGRATION_TEST_TAG)
}
}
val jacocoTestCoverageVerification = tasks.named<JacocoCoverageVerification>("jacocoTestCoverageVerification") {
violationRules {
/**
* Ensure tests cover at least 75% of the LoC.
*/
rule {
classDirectories.setFrom(files(classDirectories.files.map {
fileTree(it) {
setExcludes(listOf(
"**/com/swisscom/health/des/cdr/client/msal4j/*.class"
))
}
}))
limit {
minimum = "0.75".toBigDecimal()
}
}
}
}
val jacocoTestReport = tasks.named<JacocoReport>("jacocoTestReport") {
finalizedBy(jacocoTestCoverageVerification) // Verify after generating the report.
group = "Reporting"
reports {
xml.required.set(true)
xml.outputLocation.set(File("${outputDir.get().asFile.absolutePath}/reports/jacoco.xml"))
csv.required.set(false)
html.required.set(true)
html.outputLocation.set(File("${outputDir.get().asFile.absolutePath}/reports/coverage"))
}
}
tasks.withType<Test> {
useJUnitPlatform {
includeEngines("junit-jupiter")
}
finalizedBy(jacocoTestReport)
jvmArgs(
// tests_hosts is used to redirect msal4j, which insists on talking to the Mothership, to our docker compose setup
"-Djdk.net.hosts.file=${layout.projectDirectory.file("src/test/resources/test_hosts").asFile.absolutePath}"
)
}
jacoco {
toolVersion = jacocoVersion
}
tasks.named<BootJar>("bootJar") {
manifest {
// Required so application name and version get rendered in the banner.txt; see
// https://stackoverflow.com/questions/34519759/application-version-does-not-show-up-in-spring-boot-banner-txt
attributes("Implementation-Title" to rootProject.name)
attributes("Implementation-Version" to archiveVersion)
}
}
// https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.properties-and-configuration.expand-properties.gradle
// and https://stackoverflow.com/questions/40096007/how-to-configure-the-processresources-task-in-a-gradle-kotlin-build
tasks.processResources {
filesMatching("**/application.yaml") {
expand(project.properties)
}
}
tasks.withType<Detekt> {
baseline.set(File("${projectDir}/detekt_baseline.xml"))
reports {
xml {
required.set(true)
outputLocation.set(File("${outputDir.get().asFile.absolutePath}/reports/detekt.xml"))
}
html.required.set(false)
sarif.required.set(false)
txt.required.set(false)
}
}
/**
* Detekt
* See https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/
*/
detekt {
buildUponDefaultConfig = false // preconfigure defaults
allRules = true
parallel = true
config.setFrom(files("$rootDir/config/detekt.yml")) // Global Detekt rule set.
baseline = file("$projectDir/detekt_baseline.xml") // Module specific suppression list.
}
tasks.register("publishVersion") {
group = "publishing"
description = "Publishes boot jar"
dependsOn(tasks.withType<PublishToMavenRepository>().matching {
it.repository == publishing.repositories["GitHubPackages"] && it.publication == publishing.publications["bootJava"]
})
}
publishing {
publications {
create<MavenPublication>("bootJava") {
artifact(tasks.named("bootJar"))
}
}
repositories {
maven {
name = "GitHubPackages"
url = URI("https://maven.pkg.github.com/swisscom/cdr-client")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
/***********************
* Integration Testing *
***********************/
object Constants {
const val TASK_GROUP_VERIFICATION = "verification"
const val INTEGRATION_TEST_TAG = "integration-test"
}
tasks.register<Test>("integrationTest") {
group = Constants.TASK_GROUP_VERIFICATION
useJUnitPlatform {
includeTags(Constants.INTEGRATION_TEST_TAG)
}
shouldRunAfter(tasks.test)
// Ensure latest images get pulled
dependsOn(tasks.composePull)
}
dockerCompose {
dockerComposeWorkingDirectory.set(File("${rootProject.projectDir}/docker-compose"))
dockerComposeStopTimeout.set(Duration.ofSeconds(5)) // time before docker-compose sends SIGTERM to the running containers after the composeDown task has been started
ignorePullFailure.set(true)
isRequiredBy(tasks.getByName("integrationTest"))
}
/***************************
* END Integration Testing *
***************************/