-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.gradle
567 lines (492 loc) · 20.3 KB
/
build.gradle
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
/*
* Copyright (C) 2016-2023 the original author or authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//file:noinspection UnnecessaryQualifiedReference
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStartContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStopContainer
import com.bmuschko.gradle.docker.tasks.image.DockerPullImage
import org.sonarqube.gradle.SonarTask
import space.npstr.gradle.docker.DockerWaitHealthyContainer
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
classpath "gradle.plugin.org.flywaydb:gradle-plugin-publishing:$flywayVersion"
classpath "org.flywaydb:flyway-database-postgresql:$flywayVersion"
classpath "gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:$gradleGitVersion"
classpath "org.ajoberstar.grgit:grgit-gradle:$grGitVersion"
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:$sonarVersion"
classpath "nu.studer:gradle-jooq-plugin:$jooqPluginVersion"
classpath "org.jooq:jooq-codegen:$jooqVersion"
classpath "com.github.ben-manes:gradle-versions-plugin:$versionsPluginVersion"
classpath "com.bmuschko:gradle-docker-plugin:$dockerPluginVersion"
classpath "com.adarshr:gradle-test-logger-plugin:$testLoggerVersion"
classpath "org.siouan:frontend-gradle-plugin-jdk11:$frontendPluginVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion" //spring
}
configurations.classpath {
resolutionStrategy.activateDependencyLocking()
}
}
ext {
buildNumber = (System.getenv('CI') ? System.getenv('BUILD_NUMBER') : 'DEV')
isProd = project.hasProperty('prod')
}
configure(allprojects) {
apply plugin: 'java-library'
apply plugin: 'idea'
//set up autogenerated files in idea
compileJava {
options.annotationProcessorPath = configurations.annotationProcessor
}
idea {
module {
sourceDirs += sourceSets.main.output.generatedSourcesDirs
generatedSourceDirs += sourceSets.main.output.generatedSourcesDirs
testSources.from(sourceSets.test.output.generatedSourcesDirs)
generatedSourceDirs += sourceSets.test.output.generatedSourcesDirs
}
}
}
apply plugin: 'com.github.ben-manes.versions'
dependencyUpdates {
checkConstraints = true
resolutionStrategy {
componentSelection properReleasesOnlyOrUpdateNonStable()
}
}
static def isNonStable(String version) {
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
def regex = /^[0-9,.v-]+(-r)?(_[0-9]+)?$/
return !stableKeyword && !(version ==~ regex)
}
static def properReleasesOnlyOrUpdateNonStable() {
return { rules ->
rules.all { ComponentSelection selection ->
if (isNonStable(selection.candidate.version) && (selection.hasProperty("currentVersion") && !isNonStable(selection.currentVersion))) {
selection.reject('Release candidate')
}
}
}
}
dependencyLocking {
lockAllConfigurations()
}
// ./gradlew resolveAndLockAll --write-locks
tasks.register('resolveAndLockAll') {
doFirst {
assert gradle.startParameter.writeDependencyLocks
}
doLast {
configurations.configureEach {
resolutionStrategy {
componentSelection properReleasesOnlyOrUpdateNonStable()
}
}
configurations
.findAll { it.canBeResolved }
.each { it.resolve() }
}
}
allprojects {
apply plugin: 'org.ajoberstar.grgit'
apply plugin: 'com.adarshr.test-logger'
apply plugin: 'jacoco'
group = 'space.npstr.wolfia'
version = "${versionTag()}".toString()
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
vendor = JvmVendorSpec.ADOPTIUM
}
consistentResolution {
useCompileClasspathVersions()
}
}
repositories {
mavenCentral()
maven {
url 'https://m2.dv8tion.net/releases'
content { includeModule("net.dv8tion", "JDA") }
content { includeGroup("club.minnced") }
}
maven {
url 'https://jitpack.io'
content { includeGroup("space.npstr") }
}
}
test {
useJUnitPlatform()
jvmArgs '-XX:TieredStopAtLevel=1'
filter {
if (project.hasProperty('excludeUiTests')) {
excludeTestsMatching "*UiTest"
}
}
}
testlogger {
theme 'mocha-parallel'
showFullStackTraces true
}
jacocoTestReport {
reports {
xml.required.set(true)
}
}
defaultTasks 'build'
configurations {
globalPlatforms {
canBeResolved = false
canBeConsumed = false
}
//we want to go with undertow which supports both webflux and servlets (togglz console is a servlet)
implementation.exclude module: "spring-boot-starter-reactor-netty"
implementation.exclude module: "spring-boot-starter-tomcat"
}
configurations.configureEach {
if (canBeResolved) {
extendsFrom(configurations.globalPlatforms)
}
}
dependencies {
globalPlatforms platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion")
globalPlatforms platform("io.sentry:sentry-bom:$sentryVersion")
}
}
project(':frontend') {
apply plugin: 'org.siouan.frontend-jdk11'
frontend {
nodeVersion = "$theNodeVersion"
yarnEnabled = true
yarnVersion = "$theYarnVersion"
assembleScript = rootProject.ext.isProd ? 'run build' : 'run build --mode development'
checkScript = 'run lint --no-fix --max-warnings 0'
}
def frontendBuildCacheConfig = {
inputs.files('package.json', 'yarn.lock', 'vite.config.js')
.withPropertyName('frontendConfigFiles')
.withPathSensitivity(PathSensitivity.RELATIVE)
inputs.dir('src')
.withPropertyName('frontendSources')
.withPathSensitivity(PathSensitivity.RELATIVE)
inputs.dir('public')
.withPropertyName('frontendPublicDir')
.withPathSensitivity(PathSensitivity.RELATIVE)
}
tasks.named('assembleFrontend') {
dependsOn 'setVersion'
configure frontendBuildCacheConfig
outputs.dir(layout.buildDirectory.dir('dist'))
.withPropertyName('frontendOutput')
outputs.cacheIf { true }
}
tasks.named('checkFrontend').configure frontendBuildCacheConfig
tasks.register('setVersion', org.siouan.frontendgradleplugin.infrastructure.gradle.RunYarn) {
dependsOn tasks.named('installNode')
script.set("version --no-git-tag-version --new-version ${rootProject.version}")
}
}
apply plugin: 'application'
apply plugin: 'com.gorylenko.gradle-git-properties'
apply plugin: 'org.springframework.boot'
apply plugin: 'org.jetbrains.kotlin.plugin.spring'
apply plugin: 'kotlin'
apply plugin: 'org.sonarqube'
// db / codegen plugins
apply plugin: 'org.flywaydb.flyway'
apply plugin: 'nu.studer.jooq'
apply plugin: 'com.bmuschko.docker-remote-api'
configurations {
flywayMigration
// fucks with spring boot jar, we dont need it anyways
// be VERY careful and test the produced jar if ever reenabled
compile.exclude module: 'opus-java'
// undertow master race
implementation.exclude module: 'spring-boot-starter-reactor-netty'
implementation.exclude module: 'spring-boot-starter-tomcat'
}
ext {
codegenDbImageRepo = 'napstr/poggres'
codegenDbImageTag = "$postgresVersion"
codegenDbImageName = codegenDbImageRepo + ':' + codegenDbImageTag
codegenDbContainerName = 'wolfia-codegen-postgres'
codegenJdbcUrl = "jdbc:postgresql://127.0.0.1:5435/codegen?user=codegen"
}
dependencies {
implementation "net.dv8tion:JDA:$jdaVersion"
implementation "club.minnced:discord-webhooks:$discordWebhooksVersion"
implementation "ch.qos.logback:logback-classic"
implementation "io.sentry:sentry-logback"
implementation "io.sentry:sentry-spring-boot-starter-jakarta"
implementation "io.sentry:sentry-kotlin-extensions"
implementation "org.yaml:snakeyaml"
implementation "com.squareup.okhttp3:okhttp"
implementation "com.github.ben-manes.caffeine:caffeine"
implementation "org.json:json:$orgJsonVersion"
implementation "org.openjdk.nashorn:nashorn-core:$nashornVersion"
implementation "io.lettuce:lettuce-core"
implementation(group: "io.netty", name: "netty-transport-native-epoll", classifier: "linux-x86_64")
implementation(group: "io.netty", name: "netty-transport-native-kqueue", classifier: "osx-x86_64")
// not part of v1.3.2 BOM for some reason
implementation "io.prometheus:prometheus-metrics-instrumentation-caffeine:$prometheusClientVersion"
implementation "io.prometheus:prometheus-metrics-instrumentation-jvm"
implementation "space.npstr:prometheus_extensions:$prometheusExtensionsVersion"
implementation "io.micrometer:micrometer-registry-prometheus"
implementation "org.postgresql:postgresql"
implementation "com.zaxxer:HikariCP"
implementation "org.flywaydb:flyway-core:$flywayVersion"
implementation "org.flywaydb:flyway-database-postgresql:$flywayVersion"
implementation "net.ttddyy:datasource-proxy:$dsProxyVersion"
implementation "org.jooq:jooq:$jooqVersion"
implementation "org.jooq:jooq-codegen:$jooqVersion"
implementation "org.jooq:jooq-meta:$jooqVersion"
flywayMigration "org.postgresql:postgresql"
jooqGenerator "com.sun.xml.bind:jaxb-impl:$jaxbImplVersion"
jooqGenerator "org.glassfish.jaxb:jaxb-core:$jaxbImplVersion"
jooqGenerator "org.glassfish.jaxb:jaxb-runtime:$jaxbImplVersion"
jooqGenerator "org.postgresql:postgresql"
implementation "org.togglz:togglz-core:$togglzVersion"
implementation "org.togglz:togglz-spring-boot-starter:$togglzVersion"
implementation "org.togglz:togglz-console:$togglzVersion"
implementation "org.togglz:togglz-spring-security:$togglzVersion"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-undertow"
implementation "org.springframework.boot:spring-boot-starter-jdbc"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-oauth2-client"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.session:spring-session-data-redis"
implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation "com.fasterxml.jackson.module:jackson-module-kotlin"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
compileOnly("org.springframework.boot:spring-boot-devtools")
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8"
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude module: 'android-json' // json.org clone
}
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.testcontainers:testcontainers"
testImplementation "org.testcontainers:selenium"
testImplementation "com.codeborne:selenide:$selenideVersion"
testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
testImplementation "org.awaitility:awaitility"
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.incremental = true
options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation' << '-Xmaxerrs' << '10000' << '-Xdiags:verbose'
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions.jvmTarget = javaVersion
}
//required by spring boot configuration processor
compileJava.dependsOn(processResources)
processResources {
dependsOn ':frontend:assembleFrontend'
from(project(':frontend').layout.buildDirectory.dir('dist')) {
into 'static'
}
}
tasks.withType(SonarTask).configureEach {
dependsOn jacocoTestReport
}
springBoot {
buildInfo {
properties {
time = null
}
}
}
bootRun {
//compiling tests during bootRun increases the likelyhood of catching broken tests locally instead of on the CI
dependsOn compileTestJava
//pass in custom jvm args
// source: https://stackoverflow.com/a/25079415
// example: ./gradlew bootRun -PjvmArgs="--illegal-access=debug -Dwhatever=value"
if (project.hasProperty('jvmArgs')) {
//noinspection GroovyAssignabilityCheck
jvmArgs project.jvmArgs.split('\\s+')
}
}
bootJar {
archiveFileName = "wolfia.jar"
}
tasks.register('pullCodegenDbContainer', DockerPullImage) {
image.set(codegenDbImageName)
}
tasks.register('createCodegenDbContainer', DockerCreateContainer) {
dependsOn pullCodegenDbContainer
targetImageId(codegenDbImageName)
containerName.set(codegenDbContainerName)
hostConfig.autoRemove.set(true)
hostConfig.portBindings.set(['127.0.0.1:5435:5432'])
healthCheck.interval.set(1000 * 1_000_000L) // nanoseconds.....
withEnvVar('POSTGRES_HOST_AUTH_METHOD', 'trust')
withEnvVar('ROLE', 'codegen')
withEnvVar('DB', 'codegen')
withEnvVar('EXTENSIONS', 'hstore')
}
tasks.register('stopCodegenDbContainerPre', StopCodegenDbContainer) {
targetContainerId codegenDbContainerName
}
tasks.register('stopCodegenDbContainerPost', StopCodegenDbContainer) {
targetContainerId codegenDbContainerName
}
tasks.register('startCodegenDbContainer', DockerStartContainer) {
createCodegenDbContainer.mustRunAfter stopCodegenDbContainerPre
dependsOn(stopCodegenDbContainerPre, createCodegenDbContainer)
targetContainerId codegenDbContainerName
}
tasks.register('awaitCodegenDbContainer', DockerWaitHealthyContainer) {
dependsOn startCodegenDbContainer
targetContainerId codegenDbContainerName
awaitStatusTimeout.set(40)
}
//need two of these tasks, otherwise gradle complains about circular dependencies
class StopCodegenDbContainer extends DockerStopContainer {
StopCodegenDbContainer() {
onError { exception ->
// Ignore exception if container does not exist otherwise throw it
if (exception != null && exception.message != null //memes
&& !exception.message.contains('No such container'))
throw exception
}
}
}
def migrationsInput = fileTree('src/main/resources/db/migration')
def migrationsOutput = fileTree('build/classes/generated/java/space/npstr/wolfia/db/gen')
flyway {
tasks.withType(org.flywaydb.gradle.task.AbstractFlywayTask).configureEach {
inputs.files(migrationsInput)
.withPropertyName("flywayMigrationsInput")
.withPathSensitivity(PathSensitivity.RELATIVE)
outputs.files(migrationsOutput)
.withPropertyName("flywayMigrationsOutput")
}
flywayMigrate {
doFirst {
// running these manually in a doFirst closure ensures that they are not executed all the time
// currently there is no better way of running tasks optionally that another task depends on
pullCodegenDbContainer.start()
stopCodegenDbContainerPre.start()
createCodegenDbContainer.start()
startCodegenDbContainer.start()
awaitCodegenDbContainer.start()
}
}
url = "$codegenJdbcUrl"
locations = ['filesystem:src/main/resources/db/migration']
configurations = ['flywayMigration']
}
jooq {
version = jooqVersion
edition = nu.studer.gradle.jooq.JooqEdition.OSS
configurations {
main {
generationTool {
logging = org.jooq.meta.jaxb.Logging.WARN
jdbc {
driver = 'org.postgresql.Driver'
url = "$codegenJdbcUrl"
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
strategy {
name = 'org.jooq.codegen.DefaultGeneratorStrategy'
}
database {
name = 'org.jooq.meta.postgres.PostgresDatabase'
inputSchema = 'public'
forcedTypes {
forcedType {
userType = 'space.npstr.wolfia.db.type.OAuth2Scope[]'
converter = 'space.npstr.wolfia.db.converter.OAuth2ScopeEnumArrayConverter'
includeExpression = '.*'
includeTypes = '_OAuth2Scope'
}
forcedType {
userType = 'java.util.HashMap<java.lang.String, java.lang.String>'
binding = 'space.npstr.wolfia.db.PostgresHstoreBinding'
includeExpression = '.*'
includeTypes = 'hstore'
}
forcedType {
userType = 'java.time.Instant'
converter = '''
org.jooq.Converter.ofNullable(
java.time.OffsetDateTime.class,
java.time.Instant.class,
o -> o.toInstant(),
i -> i.atOffset(java.time.ZoneOffset.UTC))
'''
includeTypes = 'timestamp\\ with\\ time\\ zone'
}
forcedType {
userType = 'java.net.URI'
converter = 'space.npstr.wolfia.db.converter.UriConverter'
includeExpression = '.*link'
includeTypes = 'text'
}
}
}
target {
packageName = 'space.npstr.wolfia.db.gen'
directory = 'build/classes/generated/java'
}
}
}
}
}
}
generateJooq {
allInputsDeclared.set(true)
inputs.files(migrationsInput)
.withPropertyName('jooqMigrationsInput')
.withPathSensitivity(PathSensitivity.RELATIVE)
outputs.files(migrationsOutput)
.withPropertyName('jooqMigrationsOutput')
dependsOn(flywayMigrate)
doLast {
stopCodegenDbContainerPost.start()
}
}
test {
dependsOn(flywayMigrate)
doLast {
stopCodegenDbContainerPost.start()
}
}
//returns the last git tag (that needs to be in the form of MAJOR.MINOR.PATCH) and the build number
//@SuppressWarnings("GrMethodMayBeStatic")
String versionTag() {
def matcher = /^([0-9]+\.[0-9]+\.[0-9]+).*$/
def match = ("${grgit.describe()}" =~ matcher)[0]
//noinspection GroovyAssignabilityCheck
def result = match[1]
result += '-'
result += project.ext.buildNumber
println("Version: " + result)
return result
}