8

I have been developing several Grails applications over the past couple of years. I am increasingly finding that the three grails environments (dev, test, prod) aren't enough to satisfy my needs. The more "enterprisey" your application gets, the more environments you tend to have.

I tend to use 6 environments for my development cycle...

DEVA //My dev
DEVB //Team mates dev
CI_TEST //CI like Hudson QA_TEST //Testing team environment
UAT_TEST //Customers testing environment
PROD //Production

Im wondering if there is a way to define custom Grails environments? I dont think there is, but the feature could be handy.

The way I am getting around this right now is by externalising the config to a properties file.

Id imagine that this is a pretty common requirement, so how have you been dealing with your environments?

2 Answers 2

18

Config.groovy and DataSource.groovy both support custom environments (I'm pretty sure most other config files do as well).

If you want to start up your app or package it for a custom env you use

grails -Dgrails.env=myCustomEnv run-app

Then in Config you would have

environments{
    myCustomEnv{
        myProp = 'myVal'
    }
}

I couldn't find a page in the user guide about it but we use them like this to have beta and uat environment settings.

4
  • Works well, thanks! It surprises me that this isnt buried in the docs somewhere.
    – tinny
    May 19, 2010 at 21:50
  • Yeah, if you have 5 minutes it would be good to raise and issue in Grails' JIRA requesting better doco on this.
    – leebutts
    May 20, 2010 at 21:07
  • By the way, if you use multiple custom environments don't rely on Environment.current in your code: afaik it always returns CUSTOM for all of them.
    – carlosayam
    Jun 4, 2012 at 9:27
  • Environment.current.name returns the correct name as a string
    – Tobia
    May 2, 2015 at 14:06
0

One option could be to define a dataSource in DataSource.groovy for each of your environments and then store configuration information in the database.

You could then add code in BootStrap.groovy to load your configurations.

1
  • Yeah could do something like that. But part of the problem is that there are many datasources. Usually one datasource per environment, of which there are 6
    – tinny
    May 18, 2010 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.