Tuesday, March 18, 2014

GRAILS Configuration -- Different / External Config Files

External config or extra configuration files could be added your grails config.groovy file. Just replace the file names and place this piece of code right at the top of your config.groovy file.
def customConfigLocations = []
if (new File("${userHome}/.myConfig/global-config.groovy").exists()) customConfigLocations.add("file:${userHome}/.myConfig/global-config.groovy")

if (new File("${userHome}/.myConfig/${appName}-config.groovy").exists()) customConfigLocations.add("file:${userHome}/.myConfig/${appName}-config.groovy")

if (customConfigLocations.empty) {
    println("No external configuration available......")
}else {
    grails.config.locations = customConfigLocations
    println("loading configuration from: :${grails.config.locations}")
}