Skip to content

Instantly share code, notes, and snippets.

@devnulled
Created June 5, 2013 19:42
Show Gist options
  • Save devnulled/5716661 to your computer and use it in GitHub Desktop.
Save devnulled/5716661 to your computer and use it in GitHub Desktop.
Add An External Configuration File to a Grails Project

How To Create An External Configuration File in Grails

Note, this information is taken from user Big Ed at StackOverflow. Thanks Ed!

Ed's Answer

Create a properties file myExternalProperties.groovy and put it on your classpath (such as the $TOMCAT_HOME/lib directory).

Create a configuration file grails-app/conf/MyConfig.groovy to use the external configuration values (if needed). You will not be able to use the properties defined in myExternalProperties.groovy within grails-app/conf/Config.groovy.

Edit grails-app/conf/Config.groovy. Uncomment the lines the define grails.config.locations and add this:

grails.config.locations << "classpath:MyExternalProperties.groovy"
grails.config.locations << "classpath:MyConfig.groovy"

Add the following to scripts/Events.groovy (which probably needs to be created).

 eventCompileEnd = {
     ant.copy(todir:classesDirPath) {
         fileset(file:"${basedir}/grails-app/conf/MyConfig.groovy")
     }
 }

That last part is very important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment