-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
176 lines (149 loc) · 4.7 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
plugins {
kotlin("jvm") version "1.9.25"
kotlin("plugin.spring") version "1.9.25"
id("org.springframework.boot") version "3.4.0"
id("io.spring.dependency-management") version "1.1.6"
kotlin("plugin.jpa") version "1.9.25"
id("org.openapi.generator") version "7.10.0"
id("com.google.cloud.tools.jib") version "3.4.4"
id("org.flywaydb.flyway") version "11.1.0"
}
group = "language-forest"
version = "0.0.1-SNAPSHOT"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
val envName: String? by project
// 환경별 .env 파일 경로
val envFile = when(envName) {
"prod" -> file(".env.prod")
"dev" -> file(".env.dev")
"local" -> file(".env.local")
else -> file(".env.local") // 기본값 local
}
// env 파일을 읽는 로직(커스텀)
fun loadEnv(file: File): Map<String, String> {
return file.readLines()
.filter { it.contains("=") }
.map {
val (key, value) = it.split("=", limit=2)
key.trim() to value.trim()
}.toMap()
}
val envVars = loadEnv(envFile)
springBoot {
mainClass = "language_forest.LanguageForestApplicationKt"
}
jib {
from {
image = "amazoncorretto:21-alpine"
}
to {
image = "11t518s/language-forest"
tags = setOf("latest", "0.0.1")
}
container {
ports = listOf("8080")
jvmFlags = listOf("-Xms512m", "-Xmx1024m")
mainClass = "language_forest.LanguageForestApplicationKt"
}
}
repositories {
mavenCentral()
}
dependencies {
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
// Spring Boot Dependencies
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-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("io.jsonwebtoken:jjwt-api:0.12.6")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.6")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.6")
implementation("org.flywaydb:flyway-core:11.1.0")
implementation("org.flywaydb:flyway-mysql:11.1.0")
implementation("com.mysql:mysql-connector-j:8.2.0")
// Jackson Nullable
implementation("org.openapitools:jackson-databind-nullable:0.2.4")
// Validation
implementation("jakarta.validation:jakarta.validation-api:3.0.2")
implementation("org.hibernate.validator:hibernate-validator:8.0.0.Final")
// JUnit
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.flywaydb:flyway-mysql:11.1.0")
}
}
flyway {
driver = "com.mysql.cj.jdbc.Driver"
url = "jdbc:mysql://localhost:3306/db"
user = "mysql"
password = "mysql"
locations = arrayOf("filesystem:src/main/resources/db/migration")
}
// OpenAPI Generator 설정
openApiGenerate {
inputSpec.set("$rootDir/language-forest-api/api.yml") // 여기서 스펙 파일 경로 지정
generatorName.set("kotlin-spring") // Kotlin 전용 생성기 사용
outputDir.set("$rootDir/generated-language-forest-api") // build 외부 디렉토리로 변경
apiPackage.set("language_forest.generated.api")
modelPackage.set("language_forest.generated.model")
invokerPackage.set("language_forest.generated.invoker")
configOptions.put("useKotlin", "true") // Kotlin 모델 활성화
configOptions.put("library", "spring-boot")
configOptions.set(mapOf("useSpringBoot3" to "true"))
configOptions.put("documentationProvider", "none") // Swagger 및 SpringDoc 제거
configOptions.put("delegatePattern", "true") // Delegate 패턴 활성화
// configOptions.put("interfaceOnly", "true") // 인터페이스만 생성, 컨트롤러 생성 X
}
tasks.register("buildApi") {
dependsOn("openApiGenerate")
doLast {
println("API 코드가 생성되었습니다.")
}
}
//tasks.named("flywayMigrate") {
// outputs.dir(layout.buildDirectory.dir("generated").get().asFile.absolutePath)
//}
tasks.register("flywayClasspath") {
doLast {
println("Flyway Classpath:")
project.configurations.getByName("runtimeClasspath").files.forEach { file ->
println(file.absolutePath)
}
}
}
sourceSets {
main {
kotlin {
srcDir("$rootDir/generated-language-forest-api")
}
}
}
kotlin {
compilerOptions {
freeCompilerArgs.addAll("-Xjsr305=strict")
}
}
allOpen {
annotation("jakarta.persistence.Entity")
annotation("jakarta.persistence.MappedSuperclass")
annotation("jakarta.persistence.Embeddable")
}
tasks.withType<Test> {
useJUnitPlatform()
}