Back to Home or Gradle

Gradle can use the groovy yml template generator code

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
 
gradle_yml_templates.txt · Last modified: 2019/12/16 05:43 by root
 
RSS - 200 © CrosswireDigitialMedia Ltd