views:

443

answers:

1

Hi, Just wondering what is the 'best practice' when adding config key-value pairs to your grails app.

Should you just add to Config.groovy or create new files.

I tried creating a new config file (Company.groovy) but could not access the config props from my app. However when I cup-paste the properties into Config.groovy I do have access to them.... This works fine but I dont want Config.groovy to get too large. Also another problem raised its head. While running Integration tests I found that the 'test' env did not have access to my new config properties (values were null).

I must be doing something fundamentally wrong. Any advice would be appreciated.

Thanks, D

+2  A: 

I am not sure there are specific best practices. I can tell you plugins that just add a few options usually reuse Config.groovy, but ones that require more complex configuration (i.e. Nimble) typically have their own file that can be separated. So it really depends on your particular needs and amounts of configuration you want to add.

If you examine Config.groovy, you will see in the few top lines (reproduced here) that you can specify where Grails will look for configuration files. It automatically can merge property and .groovy files for you.

// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts

// grails.config.locations = [ "classpath:${appName}-config.properties",
//                             "classpath:${appName}-config.groovy",
//                             "file:${userHome}/.grails/${appName}-config.properties",
//                             "file:${userHome}/.grails/${appName}-config.groovy"]

This section in the docs describes the options for you.

Jean Barmash
Thanks Jean!Also I found a handy post on mocking config for integration tests of services (http://mrhaki.blogspot.com/2009/12/grails-goodness-mocking-configuration.html)
Derek