-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
364 lines (306 loc) · 13.2 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
import com.github.jk1.license.filter.LicenseBundleNormalizer
import com.github.jk1.license.render.InventoryHtmlReportRenderer
import com.terraformation.gradle.PostgresDockerConfigTask
import com.terraformation.gradle.VersionFileTask
import com.terraformation.gradle.computeGitVersion
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.internal.deprecation.DeprecatableConfiguration
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.internal.KaptGenerateStubsTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jooq.meta.jaxb.Strategy
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
kotlin("jvm")
kotlin("plugin.spring")
`jvm-test-suite`
// kapt is required to build the metadata for application.yaml autocomplete of our
// config settings, but slows the build down significantly; disable it by default.
// Uncomment the kapt line in the dependencies block if you enable this.
// kotlin("kapt")
id("dev.monosoul.jooq-docker") version "6.1.16"
id("com.diffplug.spotless") version "7.0.0.BETA4"
id("org.springframework.boot") version "3.4.1"
id("io.spring.dependency-management") version "1.1.7"
// Add the build target to generate Swagger docs
id("com.github.johnrengelman.processes") version "0.5.0"
id("org.springdoc.openapi-gradle-plugin") version "1.9.0"
id("com.github.jk1.dependency-license-report") version "2.9"
id("terraware-jooq")
}
buildscript {
// Force the jOOQ codegen plugin to use the same jOOQ version we use in the application code.
val jooqVersion: String by project
configurations.classpath {
resolutionStrategy {
setForcedModules(
"org.jooq:jooq-codegen:$jooqVersion",
)
}
}
// The MJML -> HTML translator for email messages is a Node.js utility. This plugin is a
// dependency of buildSrc, but we need it here as well so we can configure it.
apply(plugin = "com.github.node-gradle.node")
}
group = "com.terraformation"
version = computeGitVersion("0.1")
repositories {
maven("https://repo.osgeo.org/repository/geotools-releases/")
mavenCentral()
}
dependencies {
val awsSdkVersion: String by project
val flywayVersion: String by project
val geoToolsVersion: String by project
val jooqVersion: String by project
val jtsVersion: String by project
val ktorVersion: String by project
val postgresJdbcVersion: String by project
val springDocVersion: String by project
jooqCodegen("org.postgresql:postgresql:$postgresJdbcVersion")
// Build autocomplete metadata for our config settings in application.yaml. This
// requires kapt which slows the build down significantly, so is commented out.
// Uncomment the kotlin("kapt") line above if you enable this.
// kapt("org.springframework.boot:spring-boot-configuration-processor")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-jersey")
implementation("org.springframework.boot:spring-boot-starter-jooq")
implementation("org.springframework.boot:spring-boot-starter-mail")
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.session:spring-session-jdbc")
implementation("com.drewnoakes:metadata-extractor:2.19.0")
implementation("com.dropbox.core:dropbox-core-sdk:7.0.0")
implementation("com.google.api-client:google-api-client:2.7.1")
implementation("com.google.auth:google-auth-library-oauth2-http:1.30.1")
implementation("com.google.apis:google-api-services-drive:v3-rev20241206-2.0.0")
implementation("com.opencsv:opencsv:5.9")
implementation("com.squarespace.cldr-engine:cldr-engine:1.8.3")
implementation("commons-codec:commons-codec:1.17.2")
implementation("commons-validator:commons-validator:1.9.0")
implementation("dev.akkinoc.spring.boot:logback-access-spring-boot-starter:4.4.0") {
exclude("org.apache.tomcat")
}
implementation("io.ktor:ktor-client-auth:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-client-java:$ktorVersion")
implementation("io.ktor:ktor-serialization-jackson:$ktorVersion")
implementation("io.swagger.core.v3:swagger-annotations:2.2.27")
implementation("jakarta.inject:jakarta.inject-api:2.0.1")
implementation("jakarta.ws.rs:jakarta.ws.rs-api:4.0.0")
implementation("net.coobird:thumbnailator:0.4.20")
implementation("org.apache.tika:tika-core:3.0.0")
implementation("org.flywaydb:flyway-core:$flywayVersion")
implementation("org.flywaydb:flyway-database-postgresql:$flywayVersion")
implementation("org.freemarker:freemarker:2.3.34")
implementation("org.geotools:gt-epsg-hsql:$geoToolsVersion")
implementation("org.geotools:gt-geojson:$geoToolsVersion")
implementation("org.geotools:gt-shapefile:$geoToolsVersion")
implementation("org.geotools:gt-xml:$geoToolsVersion")
implementation("org.geotools.xsd:gt-xsd-core:$geoToolsVersion")
implementation("org.geotools.xsd:gt-xsd-kml:$geoToolsVersion")
implementation("org.jobrunr:jobrunr-spring-boot-3-starter:7.3.2")
implementation("org.jooq:jooq:$jooqVersion")
implementation("org.locationtech.jts:jts-core:$jtsVersion")
implementation("org.locationtech.jts.io:jts-io-common:$jtsVersion")
implementation(kotlin("reflect"))
implementation("org.postgresql:postgresql:$postgresJdbcVersion")
implementation(platform("software.amazon.awssdk:bom:$awsSdkVersion"))
implementation("software.amazon.awssdk:sesv2")
implementation("software.amazon.awssdk:rds")
implementation("software.amazon.awssdk:s3")
implementation("software.amazon.awssdk:sts")
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:$springDocVersion")
runtimeOnly("net.logstash.logback:logstash-logback-encoder:8.0")
testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
testImplementation("io.mockk:mockk:1.13.16")
testImplementation("org.geotools:gt-epsg-hsql:$geoToolsVersion")
testImplementation("org.hsqldb:hsqldb:2.7.4")
testImplementation("org.junit.platform:junit-platform-launcher")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation(platform("org.testcontainers:testcontainers-bom:1.20.4"))
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:postgresql")
developmentOnly("org.springframework.boot:spring-boot-devtools")
developmentOnly("com.h2database:h2")
}
configurations.configureEach {
// Spring includes its own Commons Logging implementation which can conflict with the official one
exclude("commons-logging")
}
tasks.register("downloadDependencies") {
fun ConfigurationContainer.resolveAll() =
this.filter {
it.isCanBeResolved && it !is DeprecatableConfiguration && !it.name.contains("Metadata")
}
.forEach { it.resolve() }
doLast {
configurations.resolveAll()
buildscript.configurations.resolveAll()
}
}
testing {
suites {
val test by
getting(JvmTestSuite::class) {
useJUnitJupiter()
targets {
all {
testTask.configure {
systemProperty("java.locale.providers", "SPI,CLDR")
testLogging { exceptionFormat = TestExceptionFormat.FULL }
}
}
}
}
}
}
val generateVersionFile = tasks.register<VersionFileTask>("generateVersionFile")
val generatePostgresDockerConfig =
tasks.register<PostgresDockerConfigTask>("generatePostgresDockerConfig")
val renderGibberishTask =
tasks.register<com.terraformation.gradle.RenderGibberishTask>("renderGibberish")
val renderMjmlTask = tasks.register<com.terraformation.gradle.RenderMjmlTask>("renderMjml")
tasks {
processResources {
dependsOn(renderGibberishTask)
dependsOn(renderMjmlTask)
exclude("**/*.mjml")
}
generateJooqClasses {
basePackageName = "com.terraformation.backend.db"
schemas = listOf("public", "docprod", "accelerator", "nursery", "seedbank", "tracking")
outputSchemaToDefault.add("public")
usingJavaConfig {
val generator = com.terraformation.backend.jooq.TerrawareGenerator()
val pluralStrategy = com.terraformation.backend.jooq.PluralPojoStrategy()
name = generator.javaClass.name
strategy = Strategy().withName(pluralStrategy.javaClass.name)
database.apply {
withName("org.jooq.meta.postgres.PostgresDatabase")
withIncludes(".*")
withExcludes(generator.excludes())
withForcedTypes(generator.forcedTypes(basePackageName.get()))
withEmbeddables(generator.embeddables())
// Fix compiler warnings for PostGIS functions; see https://github.com/jOOQ/jOOQ/issues/8587
withTableValuedFunctions(false)
}
generate.apply {
isDaos = true
isEmbeddables = true
isJavaTimeTypes = true
isKotlinSetterJvmNameAnnotationsOnIsPrefix = false
isPojos = true
isPojosAsKotlinDataClasses = true
isRecords = true
isRoutines = false
isSpringAnnotations = true
}
}
flywayProperties.put("flyway.placeholders.jsonColumnType", "JSONB")
flywayProperties.put("flyway.placeholders.uuidColumnType", "UUID")
}
}
jooq {
withContainer {
image {
val postgresDockerRepository: String by project
val postgresDockerTag: String by project
name = "$postgresDockerRepository:$postgresDockerTag"
}
}
}
sourceSets.main { java.srcDir("build/generated/kotlin") }
sourceSets.test { java.srcDir("build/generated-test/kotlin") }
java {
toolchain { languageVersion = JavaLanguageVersion.of(23) }
targetCompatibility = JavaVersion.VERSION_23
}
node { yarnVersion = "1.22.17" }
tasks.withType<KotlinCompile> {
compilerOptions {
// Kotlin and Java target compatibility must be the same.
jvmTarget = JvmTarget.JVM_23
allWarningsAsErrors = true
extraWarnings = true
// https://youtrack.jetbrains.com/issue/KT-72040
freeCompilerArgs.add("-Xsuppress-warning=UNUSED_ANONYMOUS_PARAMETER")
// jOOQ generated code has redundant modifiers
freeCompilerArgs.add("-Xsuppress-warning=REDUNDANT_MODALITY_MODIFIER")
freeCompilerArgs.add("-Xsuppress-warning=REDUNDANT_VISIBILITY_MODIFIER")
}
dependsOn(generateVersionFile)
if (name == "compileTestKotlin") {
dependsOn(generatePostgresDockerConfig)
}
}
tasks.withType<KaptGenerateStubsTask> { dependsOn(tasks.generateJooqClasses) }
tasks.getByName<BootJar>("bootJar") {
// Don't package local development settings in the distribution.
exclude("application-dev*.yaml")
}
spotless {
val ktfmtVersion: String by project
kotlin {
ktfmt(ktfmtVersion)
target("src/**/*.kt", "buildSrc/**/*.kt", "jooq/**/*.kt")
}
kotlinGradle {
ktfmt(ktfmtVersion)
target("*.gradle.kts", "buildSrc/*.gradle.kts", "jooq/*.gradle.kts")
}
flexmark {
target("*.md", "buildSrc/*.md", "docs/*.md", "src/**/*.md")
flexmark()
}
format("sql") {
// Only apply to newly-added SQL files since editing existing ones will cause the checksums
// to change which Flyway will detect as invalid edits of already-applied migrations.
ratchetFrom("origin/main")
target("src/**/*.sql")
endWithNewline()
trimTrailingWhitespace()
}
}
openApi {
// Run the server on a port that's unlikely to already be in use.
val listenPort = 32109
customBootRun {
// Use application-apidoc.yaml for application configuration.
jvmArgs.add("-Dspring.profiles.active=apidoc")
jvmArgs.add("-Djava.locale.providers=SPI,CLDR")
jvmArgs.add("-Dserver.port=$listenPort")
// Spring Boot Devtools aren't useful for a one-shot server run, and they add log output.
classpath.setFrom(
sourceSets.main.get().runtimeClasspath.filter { "spring-boot-devtools" !in it.name })
}
apiDocsUrl = "http://localhost:$listenPort/v3/api-docs.yaml"
outputDir = projectDir
outputFileName = "openapi.yaml"
}
tasks.register<JavaExec>("generateFrontEndTestSession") {
group = "Execution"
description = "Generates a fake login session for the frontend integration test suite."
classpath = sourceSets.test.get().runtimeClasspath
mainClass = "com.terraformation.backend.customer.FrontEndTestSessionGeneratorKt"
}
licenseReport {
configurations =
project.configurations.filter { it.isCanBeResolved }.map { it.name }.toTypedArray()
excludeBoms = true
excludes =
arrayOf(
// Spring Boot has licenses in the individual dependencies, not the umbrella artifact.
"org.springframework.boot:spring-boot-dependencies",
)
filters =
arrayOf(LicenseBundleNormalizer("$projectDir/src/docs/license-normalizer-bundle.json", true))
outputDir = "$projectDir/docs/license-report"
renderers = arrayOf(InventoryHtmlReportRenderer())
}