-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle.kts
335 lines (291 loc) · 11.5 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
@file:Suppress("GradlePackageUpdate")
plugins {
val kotlinVersion = "1.9.25"
id("org.jetbrains.kotlin.jvm") version kotlinVersion
id("org.jetbrains.kotlin.kapt") version kotlinVersion
id("org.jetbrains.kotlin.plugin.allopen") version kotlinVersion
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
id("io.micronaut.application") version "3.7.10"
id("com.diffplug.spotless") version "6.25.0"
id("io.gitlab.arturbosch.detekt") version "1.23.7"
id("com.github.spotbugs") version "6.0.24"
jacoco
id("com.adarshr.test-logger") version "4.0.0"
id("com.google.cloud.tools.jib") version "3.4.4"
id("org.owasp.dependencycheck") version "10.0.4"
}
group = "recce.server"
// Workaround to allow dependabot to update versions of libraries together, since dependabot doesn't understand
// the Gradle DSL properly. Here we pick one of the versions where multiple artifacts are released at the same time
// and use this to bump the others consistently.
val depDescriptors =
mapOf(
"micronaut" to "io.micronaut:micronaut-core:3.10.4",
"restAssured" to "io.rest-assured:rest-assured:4.5.1"
)
val depVersions =
depDescriptors.mapValues { (_, v) -> v.split(':').last() } +
mapOf(
"javaMajor" to "17",
"reactorToolsVersionExpected" to "3.6.11"
)
repositories {
mavenCentral()
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
allWarningsAsErrors = true
}
}
micronaut {
version(depVersions["micronaut"])
runtime("netty")
testRuntime("junit5")
processing {
incremental(true)
annotations("recce.server.*")
}
}
kapt {
arguments {
val props = mapOf("rapidoc.enabled" to true, "rapidoc.theme" to "dark", "rapidoc.render-style" to "view")
arg("micronaut.openapi.views.spec", props.entries.joinToString(",") { "${it.key}=${it.value}" })
}
}
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("junit:junit"))
.using(module("io.quarkus:quarkus-junit4-mock:3.0.0.Final"))
.because(
"We don't want JUnit 4; but is an unneeded transitive of testcontainers. " +
"See https://github.com/testcontainers/testcontainers-java/issues/970"
)
}
}
dependencies {
kapt("io.micronaut:micronaut-http-validation")
kapt("io.micronaut.data:micronaut-data-processor")
implementation("io.micronaut:micronaut-runtime")
implementation("io.micronaut:micronaut-validation")
implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("io.micronaut.security:micronaut-security-jwt")
constraints {
implementation("com.nimbusds:nimbus-jose-jwt:9.44")
.because("micronaut-security-jwt:3.11.1 uses an outdated version with a CVE")
}
implementation("javax.annotation:javax.annotation-api")
implementation("com.google.guava:guava:33.3.1-jre") {
// see https://github.com/google/guava/pull/6606
exclude(module = "error_prone_annotations")
exclude(module = "checker-qual")
exclude(module = "jsr305")
}
implementation("io.projectreactor:reactor-tools")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.github.microutils:kotlin-logging-jvm:2.1.23")
runtimeOnly("ch.qos.logback:logback-classic:1.2.13") // Remove fixed version when micronaut has updated to 1.3+
// Needs to be compatible with Micronaut's reactor-based BOM.
implementation(platform("io.projectreactor:reactor-bom:2023.0.11"))
// OpenAPI specification and interactive UI generated from code
kapt("io.micronaut.openapi:micronaut-openapi")
implementation("io.swagger.core.v3:swagger-annotations")
// Core persistence support with Micronaut Data
compileOnly("jakarta.persistence:jakarta.persistence-api:3.0.0")
// Traditional JDBC data access (for rec DB)
implementation("io.micronaut.flyway:micronaut-flyway")
implementation("io.micronaut.data:micronaut-data-jdbc")
implementation("io.micronaut.sql:micronaut-jdbc-hikari")
runtimeOnly("org.postgresql:postgresql:42.7.4") // Remove fixed version when micronaut has updated to 42.5.5+
// R2BDC data access (for use by all data sources)
implementation("io.micronaut.data:micronaut-data-r2dbc")
implementation("io.micronaut.r2dbc:micronaut-r2dbc-core")
runtimeOnly("io.r2dbc:r2dbc-pool")
runtimeOnly("org.postgresql:r2dbc-postgresql")
runtimeOnly("io.r2dbc:r2dbc-mssql")
runtimeOnly("dev.miku:r2dbc-mysql")
runtimeOnly("org.mariadb:r2dbc-mariadb")
runtimeOnly("com.oracle.database.r2dbc:oracle-r2dbc")
testImplementation("org.assertj:assertj-core")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testImplementation("io.projectreactor:reactor-test")
testImplementation(platform("org.mockito:mockito-bom:5.14.2")) // Needs to be compatible with Micronaut BOM
testImplementation("org.mockito:mockito-core")
testImplementation("org.mockito:mockito-junit-jupiter")
testImplementation("org.mockito.kotlin:mockito-kotlin:5.4.0")
testImplementation("io.rest-assured:rest-assured:${depVersions["restAssured"]}")
testImplementation("io.rest-assured:kotlin-extensions:${depVersions["restAssured"]}")
testImplementation("org.awaitility:awaitility-kotlin:4.2.2")
// Database testing infra
testImplementation("org.testcontainers:testcontainers")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:postgresql")
testImplementation("org.testcontainers:mysql")
testRuntimeOnly("mysql:mysql-connector-java:8.0.33") { // Remove fixed version when micronaut has updated to 8.0.33+
exclude("com.google.protobuf", "protobuf-java") // Unnecessary, we don't use this part of the driver
}
testRuntimeOnly("org.flywaydb:flyway-mysql")
testImplementation("org.testcontainers:mssqlserver")
testRuntimeOnly("com.microsoft.sqlserver:mssql-jdbc")
testRuntimeOnly("org.flywaydb:flyway-sqlserver")
testImplementation("org.testcontainers:mariadb")
testRuntimeOnly("org.mariadb.jdbc:mariadb-java-client")
testRuntimeOnly("com.h2database:h2")
// Remove version number and excludes block when Micronaut has updated to at least 1.0.0.RELEASE
testRuntimeOnly("io.r2dbc:r2dbc-h2:1.0.0.RELEASE") {
exclude("io.projectreactor", "reactor-core")
}
spotbugs("com.github.spotbugs:spotbugs:4.8.6")
spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:1.13.0")
}
dependencyCheck {
failBuildOnCVSS = 1f
suppressionFile = "build-config/dependency-check-suppressions.xml"
scanConfigurations = listOf("runtimeClasspath")
analyzers.assemblyEnabled = false // Unneeded, and creates warning noise
nvd.apiKey = System.getenv("NVD_API_KEY") ?: ""
}
application {
mainClass.set("recce.server.RecceServer")
}
tasks.run.configure {
doFirst { environment("version", "$version") }
// Workaround https://github.com/thoughtworks/recce/issues/155
jvmArgs("-XX:+StartAttachListener")
environment.computeIfAbsent("AUTH_USERNAME") { "admin" }
environment.computeIfAbsent("AUTH_PASSWORD") { "admin" }
}
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
kotlin {
ktlint()
}
kotlinGradle {
ktlint()
}
}
detekt {
config.from(files("build-config/detekt.yml"))
buildUponDefaultConfig = true
}
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
reports {
xml.required.set(false)
txt.required.set(false)
sarif.required.set(false)
}
}
spotbugs {
excludeFilter.set(file("build-config/spotbugs-exclude.xml"))
}
tasks.withType<com.github.spotbugs.snom.SpotBugsTask>().configureEach {
reports.create("html") {
required.set(true)
outputLocation.set(file("${layout.buildDirectory.get()}/reports/${this@configureEach.name}.html"))
setStylesheet("fancy-hist.xsl")
}
}
tasks.test {
finalizedBy(tasks.jacocoTestReport)
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
reports.xml.required.set(true)
}
tasks.register("cleanLeaveBuildDir") {
doLast {
project.delete(files("${layout.buildDirectory.get()}/*"))
}
}
tasks.register<Test>("slowTests") {
group = "verification"
useJUnitPlatform {
includeTags("slow")
}
}
tasks.register<Test>("fastTests") {
group = "verification"
useJUnitPlatform {
excludeTags("slow")
}
}
val githubRepoOwner = "thoughtworks"
val containerRepoName = "recce-server"
jib {
from {
image = "eclipse-temurin:${depVersions["javaMajor"]}-jre"
platforms {
platform {
architecture = "amd64"
os = "linux"
}
platform {
architecture = "arm64"
os = "linux"
}
}
}
to {
val fullVersion = com.github.zafarkhaja.semver.Version.parse(project.version.toString())
val tagVersion =
com.github.zafarkhaja.semver.Version.of(
fullVersion.majorVersion(),
fullVersion.minorVersion(),
fullVersion.patchVersion(),
fullVersion.preReleaseVersion().map { it.split('.')[0] }.orElse(null)
)
tags = setOf(tagVersion.toString(), "latest")
}
container {
user = "1000:1000"
ports = listOf("8080")
environment = mapOf("version" to version.toString())
labels.set(mapOf("org.opencontainers.image.source" to "https://github.com/$githubRepoOwner/recce"))
jvmFlags = listOf("-javaagent:/app/libs/reactor-tools-${depVersions["reactorToolsVersionExpected"]}.jar")
}
}
val checkJibDependencies =
tasks.register("checkJibDependencies") {
doFirst {
val resolvedReactorToolsVersion =
project.configurations
.runtimeClasspath
.get()
.resolvedConfiguration
.resolvedArtifacts.find { it.name == "reactor-tools" }?.moduleVersion?.id?.version
if (depVersions["reactorToolsVersionExpected"] != resolvedReactorToolsVersion) {
throw GradleException(
"Jib docker build expected reactor-tools [${depVersions["reactorToolsVersionExpected"]}] but " +
"found [$resolvedReactorToolsVersion] in dependencies. Update reactorToolsVersionExpected!"
)
}
}
}
// Jib task pushes an image. Only do so after running all checks
tasks.register<com.google.cloud.tools.jib.gradle.BuildImageTask>("jibGitHubContainerRegistry") {
dependsOn(checkJibDependencies)
dependsOn(tasks.check)
setJibExtension(project.extensions.getByName("jib") as com.google.cloud.tools.jib.gradle.JibExtension)
doFirst {
jib?.to?.image = "ghcr.io/$githubRepoOwner/$containerRepoName"
}
}
// use different naming when building locally, to avoid confusion
tasks.jibDockerBuild.configure {
dependsOn(checkJibDependencies)
jib {
from {
platforms {
platform {
architecture = if (System.getProperty("os.arch").equals("aarch64")) "arm64" else "amd64"
os = "linux"
}
}
}
to {
image = containerRepoName
}
}
}
tasks.reckonTagCreate {
dependsOn(tasks.check)
}