Skip to content

Instantly share code, notes, and snippets.

@mrserverless
Last active November 10, 2017 22:40
Show Gist options
  • Select an option

  • Save mrserverless/0526a33716091a75e7e3 to your computer and use it in GitHub Desktop.

Select an option

Save mrserverless/0526a33716091a75e7e3 to your computer and use it in GitHub Desktop.
yaml config replacement gradle, an easier way would be to use https://github.com/tkrille/dropwizard-template-config
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
apply plugin: 'groovy'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.yaml:snakeyaml:1.14'
}
}
task config << {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
def yaml = new Yaml(options)
def file = new File("platmasphere-services.yml").text
def platmasphere = (Map) yaml.load(file)
platmasphere["dataSource"]["driverClass"] = System.getenv("HIBERNATE_DRIVER") ?: platmasphere["dataSource"]["driverClass"]
platmasphere["dataSource"]["user"] = System.getenv("HIBERNATE_USER") ?: platmasphere["dataSource"]["user"]
platmasphere["dataSource"]["password"] = System.getenv("HIBERNATE_PASSWORD") ?: platmasphere["dataSource"]["password"]
platmasphere["dataSource"]["url"] = System.getenv("HIBERNATE_URL") ?: platmasphere["dataSource"]["url"]
platmasphere["dataSource"]["properties"]["hibernate.dialect"] = System.getenv("HIBERNATE_DIALECT") ?: platmasphere["dataSource"]["properties"]["hibernate.dialect"]
def platmasphereNew = yaml.dump(platmasphere)
def fileToWrite = new File("${buildDir}/platmasphere-services.yml")
fileToWrite.write(platmasphereNew)
}
config.mustRunAfter shadowJar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment