Created
May 19, 2021 01:50
-
-
Save reaperes/7b596a9c6032866f8837a00524a3fe29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
"classpath"(group = "org.yaml", name = "snakeyaml", version = "1.28") | |
} | |
} | |
flyway { | |
val yaml = org.yaml.snakeyaml.Yaml() | |
val resourceDir = sourceSets.main.get().output.resourcesDir!! | |
val appYaml = resourceDir.resolve("application.yaml") | |
val documents = yaml.loadAll(appYaml.inputStream()) | |
val localProp = getDocumentByProfile("local", documents) as? Map<String, *> | |
checkNotNull(localProp) { "Can not find local profile properties in application.yaml" } | |
val datasourceProp = ((localProp["spring"] as? Map<String, *>)?.get("datasource") as Map<String, *>) | |
url = datasourceProp["url"] as String | |
user = datasourceProp["username"] as String | |
password = datasourceProp["password"] as String | |
} | |
fun getDocumentByProfile(profile: String, documents: Iterable<Any>): Any? { | |
return documents.firstOrNull { doc -> | |
val map = doc as Map<String, *> | |
val docProfile = (map["spring"] as? Map<String, *>)?.get("config.activate.on-profile") | |
docProfile == profile | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment