-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
266 lines (225 loc) · 8.68 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
import org.hidetake.gradle.swagger.generator.GenerateSwaggerUI
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version DependencyVersion.KOTLIN
kotlin("plugin.spring") version DependencyVersion.KOTLIN
kotlin("plugin.allopen") version DependencyVersion.KOTLIN
kotlin("kapt") version DependencyVersion.KOTLIN
/** spring */
id("org.springframework.boot") version DependencyVersion.SPRING_BOOT
id("io.spring.dependency-management") version DependencyVersion.SPRING_DEPENDENCY_MANAGEMENT
/** docs */
id("org.asciidoctor.jvm.convert") version DependencyVersion.ASCIIDOCTOR
id("com.epages.restdocs-api-spec") version DependencyVersion.EPAGES_REST_DOCS_API_SPEC
id("org.hidetake.swagger.generator") version DependencyVersion.SWAGGER_GENERATOR
}
java.sourceCompatibility = JavaVersion.VERSION_18
allprojects {
group = "com.few"
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.kotlin.plugin.spring")
repositories {
mavenCentral()
}
val ktlint by configurations.creating
dependencies {
ktlint("com.pinterest.ktlint:ktlint-cli:${DependencyVersion.PINTEREST_KTLINT}") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
}
}
}
val ktlintCheck by tasks.registering(JavaExec::class) {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Check Kotlin code style"
classpath = ktlint
mainClass.set("com.pinterest.ktlint.Main")
args(
"**/src/**/*.kt",
"**.kts",
"!**/build/**",
)
}
tasks.check {
dependsOn(ktlintCheck)
}
tasks.register<JavaExec>("ktlintFormat") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Check Kotlin code style and format"
classpath = ktlint
mainClass.set("com.pinterest.ktlint.Main")
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
args(
"-F",
"**/src/**/*.kt",
"**.kts",
"!**/build/**",
)
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}
tasks.withType<Wrapper> {
gradleVersion = "8.5"
}
tasks.withType<Test> {
useJUnitPlatform()
}
sourceSets {
main {
java {
val mainDir = "src/main/kotlin"
val jooqDir = "src/generated"
srcDirs(mainDir, jooqDir)
}
}
}
}
tasks.getByName("bootJar") {
enabled = false
}
subprojects {
apply(plugin = "org.springframework.boot")
apply(plugin = "io.spring.dependency-management")
apply(plugin = "org.jetbrains.kotlin.plugin.allopen")
apply(plugin = "org.jetbrains.kotlin.kapt")
apply(plugin = "org.hidetake.swagger.generator")
apply(plugin = "org.asciidoctor.jvm.convert")
apply(plugin = "com.epages.restdocs-api-spec")
/**
* https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support
* automatically supported annotation
* @Component, @Async, @Transactional, @Cacheable, @SpringBootTest,
* @Configuration, @Controller, @RestController, @Service, @Repository.
* jpa meta-annotations not automatically opened through the default settings of the plugin.spring
*/
allOpen {
annotation("jakarta.persistence.Entity")
annotation("jakarta.persistence.MappedSuperclass")
annotation("jakarta.persistence.Embeddable")
}
dependencyManagement {
dependencies {
/**
* spring boot starter jooq 3.2.5 default jooq version is 3.18.14.
* But jooq-codegen-gradle need over 3.19.0.
* */
dependency("org.jooq:jooq:${DependencyVersion.JOOQ}")
imports {
mavenBom("org.springframework.modulith:spring-modulith-bom:${DependencyVersion.SPRING_MODULITH}")
}
}
}
dependencies {
/** spring starter */
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.modulith:spring-modulith-starter-core")
kapt("org.springframework.boot:spring-boot-configuration-processor")
/** kotlin */
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-slf4j")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
/** test **/
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.mockk:mockk:${DependencyVersion.MOCKK}")
testImplementation("com.tngtech.archunit:archunit-junit5:${DependencyVersion.ARCH_UNIT_JUNIT5}")
testImplementation("org.springframework.modulith:spring-modulith-starter-test")
testImplementation("io.qameta.allure:allure-junit5:${DependencyVersion.ALLURE_JUNIT5}")
/** kotest */
testImplementation("io.kotest:kotest-runner-junit5:${DependencyVersion.KOTEST}")
testImplementation("io.kotest:kotest-assertions-core:${DependencyVersion.KOTEST}")
testImplementation("io.kotest:kotest-framework-api:${DependencyVersion.KOTEST}")
testImplementation("io.kotest.extensions:kotest-extensions-spring:${DependencyVersion.KOTEST_EXTENSION}")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${DependencyVersion.COROUTINE_TEST}")
testImplementation("io.kotest.extensions:kotest-extensions-allure:${DependencyVersion.KOTEST_EXTENSION}")
/** Kotlin Logger **/
implementation("io.github.oshai:kotlin-logging-jvm:${DependencyVersion.KOTLIN_LOGGING}")
/** apache common */
implementation("org.apache.commons:commons-lang3:${DependencyVersion.COMMONS_LANG3}")
/** swagger ui */
swaggerUI("org.webjars:swagger-ui:${DependencyVersion.SWAGGER_UI}")
}
kapt {
includeCompileClasspath = false
}
tasks {
test {
useJUnitPlatform()
systemProperty("allure.results.directory", "$projectDir/build/allure-results")
}
register<Test>("architectureSpecTest") {
group = "spec"
useJUnitPlatform {
includeTags("ArchitectureSpec")
}
}
}
/** server url */
val serverUrl =
project.hasProperty("serverUrl").let {
if (it) {
project.property("serverUrl") as String
} else {
"http://localhost:8080"
}
}
/** convert snippet to swagger */
openapi3 {
this.setServer(serverUrl)
title = project.name
version = project.version.toString()
format = "yaml"
snippetsDirectory = "build/generated-snippets/"
outputDirectory = "src/main/resources/static"
outputFileNamePrefix = "openapi3"
}
/** convert snippet to postman */
postman {
title = project.name
version = project.version.toString()
baseUrl = serverUrl
outputDirectory = "src/main/resources/static"
outputFileNamePrefix = "postman"
}
/** generate swagger ui */
swaggerSources {
register(project.name) {
setInputFile(file("$projectDir/src/main/resources/static/openapi3.yaml"))
}
}
/**
* generate static swagger ui <br/>
* need snippet to generate swagger ui
* */
tasks.register("generateStaticSwaggerUI", Copy::class) {
val name = project.name
val generateSwaggerUITask = "generateSwaggerUI${name.first().uppercase() + name.substring(1)}"
dependsOn(generateSwaggerUITask)
val generateSwaggerUISampleTask = tasks.named(generateSwaggerUITask, GenerateSwaggerUI::class).get()
from(generateSwaggerUISampleTask.outputDir)
into("$projectDir/src/main/resources/static/docs/${project.name}/swagger-ui")
}
defaultTasks("bootRun")
}
/** git hooks */
tasks.register("gitExecutableHooks") {
doLast {
Runtime.getRuntime().exec("chmod -R +x .git/hooks/").waitFor()
}
}
tasks.register<Copy>("installGitHooks") {
val scriptDir = "${rootProject.rootDir}/scripts"
from("$scriptDir/pre-commit")
into("${rootProject.rootDir}/.git/hooks")
}
tasks.named("gitExecutableHooks").configure {
dependsOn("installGitHooks")
}
tasks.named("clean").configure {
dependsOn("gitExecutableHooks")
}