You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
2.9 KiB
108 lines
2.9 KiB
import com.fasterxml.jackson.core.type.TypeReference |
|
import com.fasterxml.jackson.databind.ObjectMapper |
|
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory |
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
|
import java.io.FileInputStream |
|
|
|
plugins { |
|
id("org.springframework.boot") version "3.2.2" |
|
id("io.spring.dependency-management") version "1.1.4" |
|
kotlin("jvm") version "1.9.22" |
|
kotlin("plugin.spring") version "1.9.22" |
|
kotlin("plugin.jpa") version "1.9.22" |
|
|
|
id("org.liquibase.gradle") version "2.2.1" |
|
} |
|
|
|
buildscript { |
|
dependencies { |
|
classpath("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.1") |
|
} |
|
} |
|
|
|
group = "com.example" |
|
version = "0.0.1-SNAPSHOT" |
|
|
|
java { |
|
sourceCompatibility = JavaVersion.VERSION_21 |
|
} |
|
|
|
repositories { |
|
mavenCentral() |
|
} |
|
|
|
dependencies { |
|
implementation("org.jetbrains.kotlin:kotlin-reflect") |
|
|
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa") |
|
implementation("org.springframework.boot:spring-boot-starter-validation") |
|
|
|
liquibaseRuntime("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.1") |
|
liquibaseRuntime("org.liquibase:liquibase-core") |
|
liquibaseRuntime("org.liquibase.ext:liquibase-hibernate6:4.25.1") |
|
liquibaseRuntime("info.picocli:picocli:4.6.3") |
|
liquibaseRuntime("com.h2database:h2") |
|
liquibaseRuntime("org.postgresql:postgresql") |
|
|
|
testImplementation("org.springframework.boot:spring-boot-starter-test") |
|
} |
|
|
|
tasks.withType<KotlinCompile> { |
|
kotlinOptions { |
|
freeCompilerArgs += "-Xjsr305=strict" |
|
jvmTarget = "21" |
|
} |
|
} |
|
|
|
tasks.withType<Test> { |
|
useJUnitPlatform() |
|
} |
|
|
|
val profile: String by project |
|
val profileDbConf = getDbConf(profile) |
|
val referencedProfile: String? by project |
|
val referencedProfileDbConf = getDbConf(referencedProfile) |
|
val defaultChangeLogFile: String by project |
|
|
|
liquibase { |
|
activities.register(profile) { |
|
this.arguments = (profileDbConf?.toMap() ?: emptyMap()) + |
|
(referencedProfileDbConf?.toReferenceMap() ?: emptyMap()) + |
|
mapOf("changelogFile" to defaultChangeLogFile) |
|
} |
|
runList = profile |
|
} |
|
|
|
data class DbConf( |
|
val url: String? = null, |
|
val username: String? = null, |
|
val password: String? = null |
|
) { |
|
fun toMap(): Map<String, String?> = mapOf( |
|
"url" to url, |
|
"username" to username, |
|
"password" to password |
|
) |
|
|
|
fun toReferenceMap(): Map<String, String?> = mapOf( |
|
"reference-url" to url, |
|
"reference-username" to username, |
|
"reference-password" to password |
|
) |
|
} |
|
|
|
fun getDbConf(profile: String?): DbConf? = profile?.let { |
|
ObjectMapper(YAMLFactory()) |
|
.readValue( |
|
FileInputStream(File(projectDir, "db.yaml")), |
|
object : TypeReference<Map<String, DbConf>>() {} |
|
)[profile] |
|
} |
|
|
|
tasks.getByName("generateChangelog").doFirst { |
|
delete(defaultChangeLogFile) |
|
} |
|
|
|
tasks.getByName("diffChangelog").doFirst { |
|
delete(defaultChangeLogFile) |
|
} |