-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
735 lines (621 loc) · 26.8 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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
import com.acme.build.*
import java.nio.charset.StandardCharsets
import java.time.format.DateTimeFormatter
buildscript {
repositories {
mavenLocal()
}
dependencies {
// ProGuard - https://www.guardsquare.com/manual/setup/gradle
classpath 'com.guardsquare:proguard-gradle:7.1.0'
// NOTE: ProGuard & JJWT -> https://github.com/jwtk/jjwt#proguard
}
}
plugins {
// ------ Java ------
id 'application'
// ------ Spring ------
// @see https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/
id 'org.springframework.boot' version "${springBootVersion}"
// @see https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/
id 'io.spring.dependency-management' version "${springBootDependenciesVersion}"
// ------ Liquibase (Generates database migrations) ------
// @see https://github.com/liquibase/liquibase-gradle-plugin
// latest version: https://plugins.gradle.org/plugin/org.liquibase.gradle
id 'org.liquibase.gradle' version '2.1.1'
// ------ IDEs ------
id 'idea'
id 'eclipse'
}
group 'com.acme'
ext {
// Default building/testing mode: production
// Look at tasks: "setupDevelopment" & "setupProduction"
development = false
// Path to "Spring Boot" property file
springBootPropsPath = "$projectDir/src/main/resources/application.properties"
h2PropsPath = "$projectDir/src/main/resources/config/application-h2.properties"
hsqlPropsPath = "$projectDir/src/main/resources/config/application-hsql.properties"
// Path to Liquibase migrations
liquibaseTempChangeLogH2 = 'src/main/resources/migrations/h2/temp-changelog.json'
liquibaseMainChangeLogH2 = 'src/main/resources/migrations/h2/main-changelog.json'
liquibaseTempChangeLogHSQL = 'src/main/resources/migrations/hsql/temp-changelog.json'
liquibaseMainChangeLogHSQL = 'src/main/resources/migrations/hsql/main-changelog.json'
temporaryDatabaseDirectory = 'temp_db'
newAuthor = 'HIBERNATE'
isHyperSQL = false
}
repositories {
// MVN Repository - https://mvnrepository.com
mavenCentral()
// BACNet4J - https://maven.mangoautomation.net/#browse/browse:ias-release ( @see https://github.com/MangoAutomation/BACnet4J#bacnet4j )
maven {
url "https://maven.mangoautomation.net/repository/ias-release/"
}
}
java {
// Set Java version compatibility when compiling Java source & when running executables (JAR, WAR, EAR,...)
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
// Build next to executable JARs, also source code & documentation
withJavadocJar()
withSourcesJar()
}
application {
mainClass = 'com.acme.onlineshop.Main'
}
configurations.all {
// Use a particular version for all dependency requests of specified package group/module
// @see https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
switch (details.requested.group) {
case 'ch.qos.logback':
details.useVersion "${logbackVersion}"
break
case 'com.fazecast':
details.useVersion "${jSerialCommVersion}"
break
case 'com.squareup.okhttp3':
// https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
details.useVersion '4.9.3'
break
case 'com.squareup.okio':
if (details.requested.name == 'okio') {
details.useVersion "${okIOVersion}"
}
break
case 'com.sun.activation':
// https://mvnrepository.com/artifact/com.sun.activation/jakarta.activation
details.useVersion '2.0.1'
break
case 'com.sun.istack':
// https://mvnrepository.com/artifact/com.sun.istack/istack-commons-runtime
details.useVersion '4.1.1'
break
case 'com.zaxxer':
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
details.useVersion '5.0.1'
break
case 'io.gsonfire':
// https://mvnrepository.com/artifact/io.gsonfire/gson-fire
details.useVersion '1.8.5'
break
case 'net.bytebuddy':
// https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy
details.useVersion '1.12.9'
break
case 'org.apache.logging.log4j':
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
details.useVersion '2.17.2'
break
case 'org.hibernate.validator':
// https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator
// ATTENTION: Higher versions do NOT work with Spring 2.6.7 !!!
details.useVersion '6.2.3.Final'
break
case 'org.jboss':
if (details.requested.name == 'jandex') {
// https://mvnrepository.com/artifact/org.jboss/jandex
details.useVersion '2.4.2.Final'
}
break
case 'org.jetbrains':
if (details.requested.name == 'annotations') {
// https://mvnrepository.com/artifact/org.jetbrains/annotations
details.useVersion '23.0.0'
}
break
case 'org.junit.jupiter':
details.useVersion "${junitJupiterVersion}"
break
case 'org.junit.platform':
details.useVersion "${junitPlatformVersion}"
break
case 'org.mockito':
// https://mvnrepository.com/artifact/org.mockito/mockito-core
details.useVersion '4.5.1'
break
case 'org.liquibase':
if (details.requested.name == 'liquibase-test-harness') {
// https://mvnrepository.com/artifact/org.liquibase/liquibase-test-harness
details.useVersion '1.0.5'
}
break
case 'org.spockframework':
// https://mvnrepository.com/artifact/org.spockframework/spock-core
details.useVersion '2.1-groovy-3.0'
break
}
}
}
dependencies {
// ---------------------------------------------------- Spring -----------------------------------------------------
// Dependencies are managed by "io.spring.dependency-management" plugin
// @see https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/
developmentOnly group: 'org.springframework.boot', name: 'spring-boot-devtools'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.session', name: 'spring-session-jdbc'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
//implementation group: 'org.springframework.security', name: 'spring-security-data'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
// implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux'
annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-configuration-processor'
// ---------------------------------------- Database (Embedded) & Hibernate ----------------------------------------
// H2 - https://mvnrepository.com/artifact/com.h2database/h2
runtimeOnly group: 'com.h2database', name: 'h2', version: '2.1.212'
// HyperSQL - https://mvnrepository.com/artifact/org.hsqldb/hsqldb
runtimeOnly group: 'org.hsqldb', name: 'hsqldb', version: '2.6.1'
// Hibernate - https://mvnrepository.com/artifact/org.hibernate/hibernate-core
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.6.8.Final'
// TODO: Update to "6.0.0.Final". Currently not working, since Hibernate has made the transition to Jakarta, but Spring NOT.
// Have to wait for Spring 6 in Q4 2022 (@see https://spring.io/blog/2021/09/02/a-java-17-and-jakarta-ee-9-baseline-for-spring-framework-6)
// ---------------------------------- Evolutionary Database - Liquibase (Gradle) -----------------------------------
// Liquibase
implementation group: 'org.liquibase', name: 'liquibase-core', version: "${liquibaseVersion}"
runtimeOnly group: 'org.liquibase.ext', name: 'liquibase-hibernate5', version: "${liquibaseVersion}"
// Liquibase (Classpath configuration)
// @see https://github.com/liquibase/liquibase-gradle-plugin#2-setting-up-the-classpath
liquibaseRuntime sourceSets.main.output
// ---------------------------------------------------- Testing ----------------------------------------------------
// JUnit 5
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${junitJupiterVersion}"
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "${junitJupiterVersion}"
// testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: "${junitJupiterVersion}"
testImplementation group: 'org.junit.vintage', name: 'junit-vintage-engine', version: "${junitJupiterVersion}"
// JUnit5 - Platform Suite (Run multiple tests at once)
// @see https://junit.org/junit5/docs/current/user-guide/#junit-platform-suite-engine
testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-launcher', version: "${junitPlatformVersion}"
testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-suite-engine', version: "${junitPlatformVersion}"
testImplementation group: 'org.junit.platform', name: 'junit-platform-suite-api', version: "${junitPlatformVersion}"
// Spring Boot - Test
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
// Spring Boot - Test(Security)
testImplementation group: 'org.springframework.security', name: 'spring-security-test'
// Spring - Test - RabbitMQ Testing - https://mvnrepository.com/artifact/org.springframework.amqp/spring-rabbit-test
// testImplementation group: 'org.springframework.amqp', name: 'spring-rabbit-test'
// Spring Boot - React Testing - https://mvnrepository.com/artifact/io.projectreactor/reactor-test
// testImplementation group: 'io.projectreactor', name: 'reactor-test', version: '3.1.0.RELEASE'
// ------------------------------------------------- Miscellaneous -------------------------------------------------
// Serial I/O for Java - jSerialComm ( https://fazecast.github.io/jSerialComm/ )
implementation group: 'com.fazecast', name: 'jSerialComm', version: "${jSerialCommVersion}"
// Enhanced I/O abilities - OK I/O ( https://square.github.io/okio/ )
runtimeOnly group: 'com.squareup.okio', name: 'okio-jvm', version: "${okIOVersion}"
// Password policy enforcement - https://mvnrepository.com/artifact/org.passay/passay
implementation group: 'org.passay', name: 'passay', version: '1.6.1'
// Bouncy Castle Provider (Cryptography API) - https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk18on
implementation group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: '1.71'
// Java JSON Web Token (JJWT)
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: "${javaJsonWebTokens}"
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: "${javaJsonWebTokens}"
implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: "${javaJsonWebTokens}"
// Thymeleaf & Spring Security integration - https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity5
implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity5', version: '3.0.4.RELEASE'
// Apache Commons Library - CSV - https://mvnrepository.com/artifact/org.apache.commons
implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.9.0'
// Apache Tika (Detect MIME type of arbitrary files) - https://mvnrepository.com/artifact/org.apache.tika/tika-core
implementation group: 'org.apache.tika', name: 'tika-core', version: '2.4.1'
// REST endpoint Documentation - OpenAPI 3.0 with Swagger UI
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: "${openAPIVersion}"
implementation group: 'org.springdoc', name: 'springdoc-openapi-security', version: "${openAPIVersion}"
}
configurations {
// Liquibase (Additional classpath configuration)
// @see https://github.com/liquibase/liquibase-gradle-plugin#2-setting-up-the-classpath
liquibaseRuntime.extendsFrom runtimeClasspath
// Integrate Spring Boot annotation processor
compileOnly.extendsFrom annotationProcessor
}
liquibase {
activities {
main {
defaultsFile 'src/main/resources/config/liquibase.properties'
}
}
}
// --------------------------------- Configure default Java & Spring Boot Gradle tasks ---------------------------------
// @see https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_tasks
tasks.withType(Jar).configureEach {
//Exclude secrets in production, but keep them in development
doFirst {
if (!development) {
processResources.exclude('secrets')
}
}
}
tasks.named('jar') {
doFirst {
if (!development) {
processResources.exclude('secrets')
}
}
manifest {
attributes(
'Implementation-Title': 'Acme Inc. Shopping',
'Implementation-Version': project.version,
'Main-Class': application.mainClass,
'Built-By': System.properties['user.name'],
'Build-Timestamp': ZonedDateTime.now().format(DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss O")),
'Build-JDK': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS': "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}",
'Gradle-Version': "${gradle.gradleVersion}"
)
}
}
tasks.named('bootJar') {
doLast() {
// Generate launch script
// @see https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#packaging-executable.configuring.launch-script
launchScript()
}
}
tasks.register('productionModeTest', Test) {
description 'Tests if the prerequisites for the "production" mode are given or not.'
group 'verification'
useJUnitPlatform()
failFast = true
doFirst {
if (!development && !project.hasProperty('dev')) {
filter {
includeTestsMatching 'i3de.communication.MainTest'
}
} else {
throw new StopExecutionException('Jump over to other tests...')
}
}
}
tasks.named('test') {
description 'Run test in "development" mode with parameter: dev'
useJUnitPlatform()
dependsOn(productionModeTest)
//mustRunAfter(productionModeTest)
testLogging {
events "passed", "skipped", "failed"
}
// filter {
// excludeTestsMatching 'i3de.communication.MainTest'
// excludeTestsMatching 'i3de.communication.readout.BitConversionSpeedTest'
// excludeTestsMatching 'i3de.communication.readout.conversion.modbus.AllConversionTests'
// excludeTestsMatching 'i3de.communication.persistence.timeseriesdatabase.influx.*'
// }
}
tasks.named('javadoc') {
// Deactivate annoying warnings for none existing DOCs
options.addStringOption('Xdoclint:none', '-quiet')
}
tasks.named('compileJava') {
options.encoding = StandardCharsets.UTF_8
}
tasks.named('compileTestJava') {
options.encoding = StandardCharsets.UTF_8
}
// ---------------------------------------------------- Custom Tasks ---------------------------------------------------
tasks.register('setupDevelopment') {
description 'Setups building environment for "development" mode.'
group "${taskGroupName}"
// Change properties dynamically: https://docs.gradle.org/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html
doFirst {
project.ext.development = true
}
}
tasks.register('setupProduction') {
description 'Setups building environment for "production" mode.'
group "${taskGroupName}"
// Change properties dynamically: https://docs.gradle.org/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html
doFirst {
project.ext.development = false
}
}
tasks.register('getVersion') {
description 'Extracts last version from "CHANGELOG.md" file & sets current project version to found version.'
group "${taskGroupName}"
def changeLog = layout.projectDirectory.file('CHANGELOG.md')
project.version = ChangeLogReader.getCurrentVersion(changeLog.asFile)
println 'Current Project Version: ' + project.version
}
tasks.register('updateVersion', WriteProperties) {
description 'Updates ".../resources/config/shop.properties" file with project version.'
group "${taskGroupName}"
dependsOn(getVersion)
outputFile = 'src/main/resources/config/shop.properties'
def oldProperties = new Properties()
outputFile.withReader { oldProperties.load(it) }
boolean wroteVersion = false
for (prop in oldProperties) {
if(prop.key == 'version') {
// Update with new project version
property 'version', project.version
wroteVersion = true
} else {
// Set old property value
property prop.key, prop.value
}
}
if(!wroteVersion) {
property 'version', project.version
}
}
tasks.register('updateReadMe') {
description 'Updates "README.md" file with current project version.'
group "${taskGroupName}"
dependsOn(getVersion)
def readMe = layout.projectDirectory.file('README.md')
doLast {
UpdateReadMe.updateReadMe(readMe.asFile, project.version)
}
}
tasks.register('generateJSONWebTokenKey') {
description 'Reads "application.properties" file and generates a new random Base64 key for the default one inside the file.'
group "${taskGroupName}"
dependsOn(copyConfigFile)
def appProperties = layout.buildDirectory.file('libs/application.properties').get()
doLast {
JWTKeyGenerator.generateRandomKey(appProperties.asFile)
}
}
tasks.register('copyConfigFile', Copy) {
description 'Copies SSL/TLS key store & user specific property file next to fat JAR, which later has to be reconfigured by end users to his system needs.'
group "${taskGroupName}"
onlyIf { !development }
mustRunAfter(build)
from layout.projectDirectory.file('src/main/resources/secrets/onlineshop.p12')
from layout.projectDirectory.file('src/main/resources/secrets/custom.properties')
into layout.buildDirectory.dir('libs')
rename('custom.properties', 'application.properties')
}
tasks.register('updateBanner') {
description 'Updates banner by adding current version & copyright text.'
group "${taskGroupName}"
dependsOn(getVersion)
def sourceBanner = layout.projectDirectory.file('src/main/resources/banner.txt')
def targetBanner = layout.buildDirectory.file('resources/main/banner.txt').get()
def license = layout.projectDirectory.file('LICENSE').asFile.getText('UTF-8')
doLast {
UpdateBanner.updateBanner(sourceBanner.asFile, targetBanner.asFile, project.version, license)
}
}
tasks.register('prepareDiffChangeLog') {
description 'Determines new target file for new liquibase changelog.'
group "${taskGroupName}"
dependsOn(buildTemporaryDatabase)
mustRunAfter(buildTemporaryDatabase)
doLast {
def liquiUtil = new LiquibaseUtil()
def newChangeLogFileName = liquiUtil.getNextChangelogFile(layout.projectDirectory.file("src/main/resources/migrations/${databaseDir}/changelogs").asFile)
def newChangeLog = "src/main/resources/migrations/${databaseDir}/changelogs/${newChangeLogFileName}"
liquibase {
activities {
main {
changeLogFile newChangeLog
}
}
}
}
}
tasks.register('reviseDiffChangeLog') {
description 'Integrates the new created changelog into the main changelog by inserting relative path, which links to new file.'
group "${taskGroupName}"
dependsOn(diffChangeLog)
mustRunAfter(diffChangeLog)
doLast {
def liquiUtil = new LiquibaseUtil()
def changeLogFile = layout.projectDirectory.file("src/main/resources/migrations/${databaseDir}/changelogs")
def changeLogFileName = liquiUtil.getLastChangelogFile(changeLogFile.asFile)
liquiUtil.updateAuthor(changeLogFile.asFile, changeLogFileName, project.ext.newAuthor, isHyperSQL)
def newChangeLog = "./changelogs/${changeLogFileName}".toString()
def mainChangeLogFile = project.layout.projectDirectory.file(liquibaseMainChangeLog)
liquiUtil.updateMainChangeLog(mainChangeLogFile.asFile, newChangeLog)
}
}
tasks.register('setMainChangeLogFile') {
description 'Sets changelog file to "main-changelog.json".'
group "${taskGroupName}"
dependsOn(setupLiquibase)
mustRunAfter(h2Properties, hsqlProperties)
doLast {
liquibase {
activities {
main {
changeLogFile project.ext.liquibaseMainChangeLog
}
}
}
}
}
tasks.register('setupLiquibase') {
description 'Reads necessary property files for given database properties'
group "${taskGroupName}"
mustRunAfter(h2Properties, hsqlProperties)
doFirst {
// Liquibase configuration
// @see https://github.com/liquibase/liquibase-gradle-plugin#3-configuring-the-plugin
liquibase {
activities {
main {
url bootURL
username "${dbUsername}"
password ""
// Adapt "Spring Boot" DB column naming strategy
// @see https://github.com/liquibase/liquibase-hibernate/wiki#spring-boot
referenceUrl "hibernate:spring:i3de.communication.persistence?dialect=${bootDialect}" +
'&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy' +
'&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
defaultsFile 'src/main/resources/config/liquibase.properties'
changeLogFile liquibaseTempChangeLog
}
}
}
}
}
tasks.register('hsqlProperties') {
description 'Reads necessary property files for HyperSQL database and setups properties in preparation of migration.'
group "${taskGroupName}"
// Liquibase configuration
// @see https://github.com/liquibase/liquibase-gradle-plugin#3-configuring-the-plugin
doFirst {
// Read "Spring Boot" application.properties
Properties springBootProperties = new Properties()
file(springBootPropsPath).withInputStream { springBootProperties.load(it) }
file(hsqlPropsPath).withInputStream { springBootProperties.load(it) }
// HyperSQL setup properties
project.ext.bootURL = springBootProperties.getProperty('spring.datasource.url')
project.ext.migrationURL = "jdbc:hsqldb:file:${temporaryDatabaseDirectory}/liquibase_changelog"
project.ext.dbUsername = ''
project.ext.bootDialect = springBootProperties.getProperty('spring.jpa.database-platform')
project.ext.databaseDir = 'hsql'
project.ext.liquibaseMainChangeLog = liquibaseMainChangeLogHSQL
project.ext.liquibaseTempChangeLog = liquibaseTempChangeLogHSQL
project.ext.isHyperSQL = true
}
}
tasks.register('h2Properties') {
description 'Reads necessary property files for H2 database and setups properties in preparation of migration.'
group "${taskGroupName}"
doFirst {
// Read "Spring Boot" application.properties
Properties springBootProperties = new Properties()
file(springBootPropsPath).withInputStream { springBootProperties.load(it) }
file(h2PropsPath).withInputStream { springBootProperties.load(it) }
// H2 setup properties
project.ext.bootURL = springBootProperties.getProperty('spring.datasource.url').split(';')[0]
project.ext.migrationURL = "jdbc:h2:file:./${temporaryDatabaseDirectory}/liquibase_changelog"
project.ext.dbUsername = springBootProperties.getProperty('spring.datasource.username')
project.ext.bootDialect = springBootProperties.getProperty('spring.jpa.database-platform')
project.ext.databaseDir = 'h2'
project.ext.liquibaseMainChangeLog = liquibaseMainChangeLogH2
project.ext.liquibaseTempChangeLog = liquibaseTempChangeLogH2
}
}
tasks.register('deleteDerbyLog') {
description 'Deletes empty "derby.log" file, which is automatically generated from Liquibase tasks.'
group "${taskGroupName}"
doLast {
// Bug: Plugin (Liquibase) generates an empty "derby.log" in project root directory
// @see https://github.com/liquibase/liquibase/issues/2196
delete 'derby.log'
}
}
tasks.register('setNewDatabaseURL') {
description 'Sets target URL to new location.'
group "${taskGroupName}"
dependsOn(setupLiquibase)
doLast {
liquibase {
activities {
main {
url migrationURL
}
}
}
}
}
tasks.register('buildTemporaryDatabase') {
description 'Builds a new (temporary) database & populates with latest changelog files for migration process.'
group "${taskGroupName}"
dependsOn(setupLiquibase, setNewDatabaseURL)
}
tasks.register('deleteTemporaryDatabase') {
description 'Deletes temporary database from migration process.'
group "${taskGroupName}"
mustRunAfter(reviseDiffChangeLog)
doLast {
delete temporaryDatabaseDirectory
}
}
tasks.register('BuildDevelopment') {
description 'Build application in "development" mode.'
group "${taskGroupName}"
dependsOn(setupDevelopment, build, updateVersion, updateReadMe)
}
tasks.register('BuildProduction') {
description 'Build application in "production" mode.'
group "${taskGroupName}"
dependsOn(setupProduction, build, updateVersion, updateReadMe, updateBanner, generateJSONWebTokenKey)
}
tasks.register('MakeHSQLMigrations') {
description 'Migrates any new database changes to change log files, that later can be consumed by the application when runnning with HyperSQL database.'
group "${taskGroupName}"
finalizedBy(deleteTemporaryDatabase, deleteDerbyLog)
dependsOn(hsqlProperties, buildTemporaryDatabase, prepareDiffChangeLog, diffChangeLog, reviseDiffChangeLog)
}
tasks.register('MakeH2Migrations') {
description 'Migrates any new database changes to change log files, that later can be consumed by the application when runnning with H2 database.'
group "${taskGroupName}"
finalizedBy(deleteTemporaryDatabase, deleteDerbyLog)
dependsOn(h2Properties, buildTemporaryDatabase, prepareDiffChangeLog, diffChangeLog, reviseDiffChangeLog)
}
tasks.register('MigrateHyperSQL') {
description 'Pushes any changes that are in the changelog files and that have not been deployed to the HyperSQL database yet.'
group "${taskGroupName}"
dependsOn(hsqlProperties, setMainChangeLogFile, update)
}
tasks.register('MigrateH2') {
description 'Pushes any changes that are in the changelog files and that have not been deployed to the H2 database yet.'
group "${taskGroupName}"
dependsOn(h2Properties, setMainChangeLogFile, update)
}
tasks.register('DeleteMigrationsFromHyperSQL') {
description 'Drops ALL tables from database.'
group "${taskGroupName}"
dependsOn(hsqlProperties, setMainChangeLogFile, dropAll)
}
tasks.register('DeleteMigrationsFromH2') {
description 'Drops ALL tables from database.'
group "${taskGroupName}"
dependsOn(h2Properties, setMainChangeLogFile, dropAll)
}
// ------------------------------------------------ Task orchestration -------------------------------------------------
// @see https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:ordering_tasks
// @see https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:finalizer_tasks
build.configure {
dependsOn(getVersion)
mustRunAfter(setupDevelopment, setupProduction)
}
processResources.configure { mustRunAfter(updateVersion) }
sourcesJar.configure { mustRunAfter(updateVersion) }
diffChangeLog.configure { mustRunAfter(prepareDiffChangeLog) }
update.configure {
mustRunAfter(setMainChangeLogFile)
finalizedBy(deleteDerbyLog)
}
dropAll.configure {
mustRunAfter(setMainChangeLogFile)
finalizedBy(deleteDerbyLog)
}
diffChangeLog.configure {
// This is necessary for the Hibernate entities. They can only be recognize by Liquibase if the Java code is compiled!!!
dependsOn(compileJava)
// Ignore "Spring Boot" session tables
// @see https://docs.liquibase.com/workflows/liquibase-community/including-and-excluding-objects-from-a-database.html
doLast {
liquibase {
activities {
main {
excludeObjects "SPRING_SESSION,SPRING_SESSION_ATTRIBUTES"
}
}
}
}
}