4

I'd like to append the env name on each war i build automatically (grails [dev|test|prod] war

I tried to do the following in BuildConfig.groovy but nothing changed:

switch (grails.util.GrailsUtil.environment) {

    case "development":
        grails.project.war.file = "target/${appName}-dev-${appVersion}" 
    case "test":
        grails.project.war.file = "target/${appName}-test-${appVersion}"
    case "production":
        grails.project.war.file = "target/${appName}-prod-${appVersion}"
}

Any thoughts? of course I can change it manually on the command line but i'd thought i'd do it a little cleaner if possible...

Jon
  • 1,039
  • 2
  • 11
  • 16

2 Answers2

12

GrailsUtil.environment is deprecated - use grails.util.Environment.current.name instead.

This is failing because of a timing issue - GrailsUtil.environment isn't set yet so none of the cases match. Even if they were you'd have a problem since you have no break statements - you need one for each case.

This works (although it uses the full name, e.g. 'production' or 'development'):

grails.project.war.file = "target/${appName}-${grails.util.Environment.current.name}-${appVersion}.war"
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
1

You can also do something like this:

grails.project.war.file = "target/${appName}${grails.util.Environment.current.name == 'development' ? '-dev' : ''}.war"