Grails multi-version launch script
Note: The latest version of the script below is on github.
I work with grails quite a lot these days. I have about 5 plugins and over 10 projects that I currently work on frequently. Fairly inevitably they use an assortment of grails versions. Manually chopping and changing command lines to execute different versions gets pretty tedious.
The solution - have a grails wrapper script that detects the version of grails defined in the current project and runs the right one.
This wasn't my idea, but when I finally got fed up with manually juggling grails versions I couldn't find where I had read about it previously. So I decided to write my own version.
This relies on putting all of the grails releases that you want to support into /usr/local/grails/ using the directory names that come in the distribution file (ie grails-x.x.x). Then just create /usr/local/bin/grails with the following content:
#!/bin/bash
BASE=/usr/local/grails
APP=application.properties
VER=$1
if [ -d "$BASE/grails-$VER" ]; then
shift
else
if [ -f $APP ]; then
VER=`grep app.grails.version $APP | cut -d= -f2`
if [ ! -d "$BASE/grails-$VER" ]; then
echo Detected version $VER could not be found
exit 1
fi
else
echo No valid version on command line and no $APP file found
exit 1
fi
fi
export GRAILS_HOME=$BASE/grails-$VER
$BASE/grails-$VER/bin/grails $*
In existing projects you can just run "grails" and it will pick the right version - assuming you have it installed. If you want to override the automatic choice (eg when upgrading the project) you can specify a version as the first parameter:
grails 1.3.7 upgrade
Likewise when not in a project (eg when creating a new one) you can do the same thing:
grails 1.3.5 create-app