Grails Override Configuration with Properties File

Posted by Jen Tong on April 6, 2010

Sometimes you will need to switch up configuration in a hurry. For example, you may need to switch the database connection URL in order to use your warm standby database. This can be a pain in Grails because the convient-during-development Config.groovy is compiled both by grails run-app and grails war.

The simplest way to change configuration without rebuilding and redeploying your Grails application is to make use of an externalized configuration file. Although would appear to be very straight forward based on the docs, you will need to jump through a couple undocumented hoops to get it working in all environments.

  1. Create your override configuration file in the grails-app/conf folder. I called mine override.conf. For now you can leave it empty.
  2. Enable this external configuration file by pasting this into the top of your grails-app/conf/Config.groovy file:
grails.config.locations = [ ""  ]

This is where the docs end. When you start up grails you’ll see the following error message:

Unable to load specified config location : class path resource [] cannot be opened because it dosn't exist
  1. Grails uses different paths in run-app mode and when being run as a war. We’re going to need to add a step post compilation to ensure our configuration file is available at all times. We’ll do this by modifying _Events.groovy (or Events.groovy if you’ve been migrating your grails app since v1.1). Open scripts/_Events.groovy, or create it if it does not exist.
  2. Add the following to _Events.groovy (or merge it in if you already have an eventCompileEnd defined):
eventCompileEnd = {
    ant.copy(todir:classesDirPath) {
  1. Try setting a new property and fire up grails as usual. For example, if you want to set the database URL, you’d add this to your grails-app/conf/ file:

Source: Some Grails - user mailing list post by Ian Roberts