Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails war filename based on environment

Tags:

grails

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...

like image 300
Jon Avatar asked Dec 12 '22 15:12

Jon


2 Answers

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"
like image 81
Burt Beckwith Avatar answered Jan 29 '23 23:01

Burt Beckwith


You can also do something like this:

grails.project.war.file = "target/${appName}${grails.util.Environment.current.name == 'development' ? '-dev' : ''}.war"
like image 26
user3253378 Avatar answered Jan 30 '23 00:01

user3253378