Jun
17
2010

Change your current Grails version with a simple shell script

Working with applications on multiple versions of Grails can be a pain. First you have to set your GRAILS_HOME environment variable, and then you have to make sure that the grails shell script (or grails.bat) is in your path. Since I have to switch versions frequently, I whipped up a simple shell script to make this easy. This is *nix specific (and may even be bash-specific), but it works for me.

Usage

$ ./setGrailsVersion 1.3.2
$ grails
Welcome to Grails 1.3.2 - http://grails.org/
Licensed under Apache Standard License 2.0
.......

$ ./setGrailsVersion 1.2.2
$ grails
Welcome to Grails 1.2.2 - http://grails.org/
Licensed under Apache Standard License 2.0
.......

Prerequisites:

  • Unzip your versions of grails side-by-side in a known directory. I use ~/grailsBase, so a valid install would be ~/grailsBase/grails-1.3.2
  • Leave your GRAILS_HOME environment variable set to ~/grailsBase/grails
  • Leave your PATH environment variable with an entry to ~/grailsBase/grails/bin
  • Save this script along side your installs. For me, this means I save it at ~/grailsBase/setGrailsVersion.sh

Script:

#!/bin/sh

##
## Switches grails versions by changing the the symlink ~/grails to a
## ~/grails-$VERSION
##
## Author: Dan Lynn (dan@danlynn.com)
##

if [ -z "$1" ]; then
	cat <<End-of-message
Usage:
	$0 [version]

The version argument must be a valid grails installation and comes in the standard grails versioning scheme.

Examples:
	$0 1.3.2
	$0 1.2.2

End-of-message

	exit 1
fi

DIRNAME=`dirname "$0"`
NEW_GRAILS_HOME="$DIRNAME/grails-$1"

if [ ! -d $NEW_GRAILS_HOME ]; then
	echo "$NEW_GRAILS_HOME doesn't exist!" >&2
	exit 1
fi

rm "$DIRNAME/grails"
ln -s $NEW_GRAILS_HOME "$DIRNAME/grails"
Written by Dan in: General |

No Comments »

RSS feed for comments on this post. TrackBack URL


Leave a Reply

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com