-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
182 lines (153 loc) · 5.65 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
import com.adarshr.gradle.testlogger.theme.ThemeType
import com.github.jk1.license.filter.LicenseBundleNormalizer
buildscript { repositories { mavenCentral() } }
plugins {
alias(libs.plugins.spring.boot)
alias(libs.plugins.spring.dependency.management)
id("java")
alias(libs.plugins.spotless)
id("jacoco")
alias(libs.plugins.sonarqube)
alias(libs.plugins.dependency.license.report)
alias(libs.plugins.test.logger)
alias(libs.plugins.versions)
alias(libs.plugins.version.catalog.update)
}
group = "de.bund.digitalservice"
version = "0.0.1-SNAPSHOT"
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
configurations { compileOnly { extendsFrom(annotationProcessor.get()) } }
repositories { mavenCentral() }
jacoco { toolVersion = libs.versions.jacoco.get() }
testlogger { theme = ThemeType.MOCHA }
dependencies {
implementation(libs.spring.boot.starter.actuator)
implementation(libs.spring.boot.starter.security)
implementation(libs.spring.boot.starter.webflux)
implementation(libs.netty.common)
compileOnly(libs.lombok)
developmentOnly(libs.spring.boot.devtools)
annotationProcessor(libs.lombok)
testImplementation(libs.spring.boot.starter.test)
testImplementation(libs.reactor.test)
testImplementation(libs.spring.security.test)
testImplementation(libs.archunit.junit5)
testImplementation(libs.mockito.junit.jupiter)
}
tasks {
register<Test>("integrationTest") {
description = "Runs the integration tests."
group = "verification"
useJUnitPlatform {
includeTags("integration")
}
// So that running integration test require running unit tests first,
// and we won"t even attempt running integration tests when there are
// failing unit tests.
dependsOn(test)
finalizedBy(jacocoTestReport)
}
check {
dependsOn("integrationTest")
}
bootBuildImage {
val containerRegistry = System.getenv("CONTAINER_REGISTRY") ?: "ghcr.io"
val containerImageName = System.getenv("CONTAINER_IMAGE_NAME") ?: "digitalservicebund/${rootProject.name}"
val containerImageVersion = System.getenv("CONTAINER_IMAGE_VERSION") ?: "latest"
imageName.set("$containerRegistry/$containerImageName:$containerImageVersion")
builder.set("paketobuildpacks/builder-jammy-tiny")
publish.set(false)
docker {
publishRegistry {
username.set(System.getenv("CONTAINER_REGISTRY_USER") ?: "")
password.set(System.getenv("CONTAINER_REGISTRY_PASSWORD") ?: "")
url.set("https://$containerRegistry")
}
}
}
jacocoTestReport {
// Jacoco hooks into all tasks of type: Test automatically, but results for each of these
// tasks are kept separately and are not combined out of the box. we want to gather
// coverage of our unit and integration tests as a single report!
executionData.setFrom(
files(
fileTree(project.buildDir.absolutePath) {
include("jacoco/*.exec")
},
),
)
reports {
xml.required = true
html.required = true
}
dependsOn("integrationTest") // All tests are required to run before generating a report.
}
jar {
// We have no need for the plain archive, thus skip creation for build speedup!
enabled = false
}
getByName("sonar") {
dependsOn("jacocoTestReport")
}
test { useJUnitPlatform { excludeTags("integration") } }
withType(com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask::class) {
fun isStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
return stableKeyword || regex.matches(version)
}
gradleReleaseChannel = "current"
revision = "release"
rejectVersionIf { !isStable(candidate.version) }
}
}
spotless {
java {
removeUnusedImports()
googleJavaFormat()
}
kotlinGradle {
ktlint()
}
format("misc") {
target(
"**/*.js",
"**/*.json",
"**/*.md",
"**/*.properties",
"**/*.sh",
"**/*.yml",
)
prettier(
mapOf(
"prettier" to "2.6.1",
"prettier-plugin-sh" to "0.7.1",
"prettier-plugin-properties" to "0.1.0",
),
).config(mapOf("keySeparator" to "="))
}
}
sonar {
// NOTE: sonarqube picks up combined coverage correctly without further configuration from:
// build/reports/jacoco/test/jacocoTestReport.xml
properties {
property("sonar.projectKey", "digitalservicebund_java-application-template")
property("sonar.organization", "digitalservicebund")
property("sonar.host.url", "https://sonarcloud.io")
}
}
licenseReport {
// If there's a new dependency with a yet unknown license causing this task to fail
// the license(s) will be listed in build/reports/dependency-license/dependencies-without-allowed-license.json
allowedLicensesFile = File("$projectDir/allowed-licenses.json")
filters =
arrayOf(
// With second arg true we get the default transformations:
// https://github.com/jk1/Gradle-License-Report/blob/7cf695c38126b63ef9e907345adab84dfa92ea0e/src/main/resources/default-license-normalizer-bundle.json
LicenseBundleNormalizer(null as String?, true),
)
}