Dark theme | Light theme

January 24, 2010

Grails Goodness: Simple Script to Create WAR Files for Each Environment

We can create a new WAR file with the following Grails command:

$ grails test war dist/test.war

This will make a new WAR file in the dist directory with the name test.war. We use the test environments for the settings.

With the following Groovy script we create a WAR file in the dist for each environment. We use to get the application name and version and use it to create the WAR filename.

// File: createwar.groovy
// Run with: $ groovy createwar.groovy
def ant = new AntBuilder()

// Read properties. file: ''

def appVersion ='app.version'
def appName =''

def envs = ['dev', 'test', 'prod', 'testserver1', 'testserver2']
envs.each { env ->
    def grailsEnv = env
    ant.exec(executable: 'grails') {
        arg(value: "-Dgrails.env=${grailsEnv}")
        arg(value: 'war')
        arg(value: "dist/${appName}-${appVersion}-${grailsEnv}.war")