Last active
November 10, 2017 22:40
-
-
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
This file contains hidden or 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
| 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