Showing posts with label Grails. Show all posts
Showing posts with label Grails. Show all posts

Tuesday, February 22, 2011

Manage multiple Grails versions in development

In Grails development, it's not uncommon to maintain several projects with different Grails versions.

It's a PITA to switch between Grails versions during development. Because it requires GRAILS_HOME to be updated, to point to the correct Grails directory.


Rescue My Ass
I added 2 new bash commands to make my life easy:
  • grls - list all available installed versions.
  • gr <version> - set GRAILS_HOME to the specified version.

How to Use
Beech-Forkers-MacBook:~ huiming$ grls
1.1.2
1.3.2
1.3.4
1.3.6
Beech-Forkers-MacBook:~ huiming$ gr 1.3.2
Beech-Forkers-MacBook:~ huiming$ grails
Welcome to Grails 1.3.2 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /Users/huiming/work/tools/grails

How I Implement
First, I keep all Grails installations under a same directory:
Beech-Forkers-MacBook:~ huiming$ ls -d1 work/tools/grails-*
work/tools/grails-1.1.2
work/tools/grails-1.3.2
work/tools/grails-1.3.4
work/tools/grails-1.3.6

Then, add the commands into my ~/.profile file:
TOOLS=~/work/tools

function gr {
  rm -f $TOOLS/grails && ln -s $TOOLS/grails-$1 $TOOLS/grails
}
alias grls="ls -d $TOOLS/grails-* | xargs basename | sed 's/grails-//g'"

export GRAILS_HOME=$TOOLS/grails
PATH=$GRAILS_HOME/bin:$PATH

Thanks to Jeffs, as the idea is largely based on his solution.