-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
224 lines (188 loc) ยท 6.08 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
buildscript {
dependencies {
classpath("${libs.testcontainers.postgresql.get()}")
classpath("${libs.flyway.database.postgresql.get()}")
}
}
plugins {
java
alias(libs.plugins.spring.boot)
alias(libs.plugins.spring.dependency.management)
alias(libs.plugins.spotless)
alias(libs.plugins.flyway)
alias(libs.plugins.jooq)
}
group = "com.dnd"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
dependencies {
// Version๋ค์ gradle/libs.versions.toml ํ์ผ์์ ๊ด๋ฆฌํฉ๋๋ค.
implementation(libs.bundles.spring.boot)
implementation(libs.dotenv)
implementation(libs.jetbrains.annotations)
implementation(libs.springdoc)
implementation(libs.bcpkix)
//defect detection tool for Java that uses static analysis to look for more than 200 bug patterns
implementation(libs.spotbugs)
// JWT
implementation(libs.jjwt.api)
runtimeOnly(libs.jjwt.impl)
runtimeOnly(libs.jjwt.jackson)
// Database
implementation(libs.postgresql)
runtimeOnly(libs.postgresql)
implementation(libs.hibernate.spatial)
implementation(libs.flyway.core)
runtimeOnly(libs.flyway.database.postgresql)
// jOOQ
implementation(libs.bundles.jooq)
jooqCodegen(libs.postgresql)
// Lombok
implementation(libs.lombok)
annotationProcessor(libs.lombok)
testCompileOnly(libs.lombok)
testAnnotationProcessor(libs.lombok)
implementation(libs.caffeine)
implementation(libs.resilience4j.spring.boot)
implementation(libs.bundles.logback)
runtimeOnly(libs.micrometer.registry.prometheus)
testImplementation(libs.bundles.spring.boot.test)
testImplementation(libs.bundles.testcontainers)
testRuntimeOnly(libs.junit.platform.launcher)
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.bootBuildImage {
createdDate = "now"
doFirst {
version = imageName.get().substringAfterLast(":", "Unknown")
println("Setting version to: $version")
}
}
springBoot.buildInfo { properties {} }
spotless {
encoding = Charsets.UTF_8
java {
target("**/*.java")
targetExclude("build/**", "**/*Request*.java", "**/*Response*.java", "**/*Dto*.java")
palantirJavaFormat("2.47.0")
}
java {
target("**/*.java")
endWithNewline()
indentWithSpaces(4)
trimTrailingWhitespace()
importOrder("", "java|javax", "\\#").wildcardsLast()
removeUnusedImports()
}
format("misc") {
// define the files to apply `misc` to
target("*.gradle", "*.gradle.*", ".gitattributes", ".gitignore")
// define the steps to apply to those files
endWithNewline()
indentWithSpaces(4)
trimTrailingWhitespace()
}
}
tasks.register<Copy>("updateGitHooks") {
from("scripts/pre-commit.sh")
into(".git/hooks")
rename("pre-commit.sh", "pre-commit")
doLast {
val preCommitHook = file(".git/hooks/pre-commit")
preCommitHook.setExecutable(true, false)
}
}
tasks.compileJava {
dependsOn("updateGitHooks")
dependsOn(tasks.jooqCodegen)
}
tasks.register("projectTest") {
dependsOn(tasks.spotlessCheck)
dependsOn(tasks.compileJava)
dependsOn(tasks.test)
}
// Here we register service for providing our database during the build.
val dbContainerProvider = project.gradle.sharedServices.registerIfAbsent("postgres", PostgresService::class) {}
tasks.flywayMigrate {
usesService(dbContainerProvider)
locations = arrayOf("filesystem:src/main/resources/db/migration")
inputs.files(fileTree("src/main/resources/db/migration"))
doFirst {
val dbContainer = dbContainerProvider.get().container()
url = dbContainer.jdbcUrl
user = dbContainer.username
password = dbContainer.password
}
}
afterEvaluate {
// For jOOQ to run we always need for flyway to be completed before.
tasks.jooqCodegen {
dependsOn(tasks.flywayMigrate)
doFirst {
val dbContainer = dbContainerProvider.get().container()
jooq.configuration {
jdbc = org.jooq.meta.jaxb.Jdbc().apply {
driver = "org.postgresql.Driver"
url = dbContainer.jdbcUrl
user = dbContainer.username
password = dbContainer.password
}
}
}
doLast {
dbContainerProvider.orNull?.close()
}
}
}
jooq {
configuration {
logging = org.jooq.meta.jaxb.Logging.WARN
generator {
name = "org.jooq.codegen.DefaultGenerator"
database {
name = "org.jooq.meta.postgres.PostgresDatabase"
includes = ".*"
excludes = "flyway_schema_history"
inputSchema = "public"
forcedTypes {
forcedType {
userType = "com.dnd.runus.global.constant.MemberRole"
includeExpression = ".*\\.role"
}
forcedType {
userType = "com.dnd.runus.global.constant.SocialType"
includeExpression = ".*\\.social_type"
}
forcedType {
userType = "com.dnd.runus.global.constant.RunningEmoji"
includeExpression = ".*\\.emoji"
}
}
}
target {
packageName = "${group}.runus.jooq"
directory = "target/generated-sources/jooq"
}
}
}
}
// Build service for providing database container.
abstract class PostgresService : BuildService<BuildServiceParameters.None>, AutoCloseable {
private val container = org.testcontainers.containers.PostgreSQLContainer<Nothing>(
org.testcontainers.utility.DockerImageName.parse(
"imresamu/postgis:16-3.4-alpine"
).asCompatibleSubstituteFor("postgres")
).apply {
start()
}
override fun close() = container.stop()
fun container() = container
}