How to use external .groovy config file in Grails 3
I found this thread and quotation by Graeme Rocher:
Grails 3 uses Spring's property sources concept, so it will resolve properties from the system, the environment and finally the application.yml/application.groovy
and code by Clyde Balneaves:
class Application extends GrailsAutoConfiguration implements EnvironmentAware {
static void main(String[] args) {
GrailsApp.run(Application)
}
@Override
void setEnvironment(Environment environment) {
//Set up Configuration directory
def krakenHome = System.getenv('KRAKEN_HOME') ?: System.getProperty('KRAKEN_HOME') ?: "/opt/kraken"
println ""
println "Loading configuration from ${krakenHome}"
def appConfigured = new File(krakenHome, 'KrakenConfig.groovy').exists()
println "Loading configuration file ${new File(krakenHome, 'KrakenConfig.groovy')}"
println "Config file found : " + appConfigured
if (appConfigured) {
def config = new ConfigSlurper().parse(new File(krakenHome, 'KrakenConfig.groovy').toURL())
environment.propertySources.addFirst(new MapPropertySource("KrakenConfig", config))
}
}
}