Switching Versions Of Grails (and other tools) Friday, April 23, 2010

I have a little trick that I have used for many years to switch back and forth between versions of development tools. For example, because of the work that I do day to day I often need to switch back and forth between different versions of Grails. Occasionally I will execute this trick while sitting with another developer or during a live coding presentation at a conference without even thinking about it. Often someone will notice and and stop me to ask "what was that?".

I have a directory below my HOME directory called Tools. This Tools directory is where I install development tools like Groovy, Grails, Gradle, Ant etc. For some of those tools, I may want to have numerous versions of the tool available. For example, I have the following subdirectories below Tools...


grails-1.0.5
grails-1.1.1
grails-1.1.2
grails-1.2-M4
grails-1.2.0
grails-1.2.0.RC1
grails-1.2.0.RC2
grails-1.2.1
grails-1.2.2
grails-1.3.0.RC1
grails-1.3.0.RC2


One thing I might do when I need to use a specific version of Grails is something like this...


export GRAILS_HOME=~/Tools/grails-1.2.2
export PATH=$GRAILS_HOME/bin:$PATH


One limitation of that approach is it is a lot of tedious typing. Another is that the change would only apply to the shell where that was executed. Normally if I am working with a particular version of Grails, I want that version to be in play in all open shells.

Instead of pointing GRAILS_HOME at a particular version of Grails, I create a symlink at ~/Tools/grails and that link points to one of the specific Grails version directories. GRAILS_HOME points to that symlink. If I am currently using Grails 1.2.2 and I want to switch to 1.3.0.RC2, I just move the symlink and leave GRAILS_HOME and PATH alone.

Moving the symlink is easy enough but I simplify it further by defining aliases in my ~/.profile. Those look something like this...


alias gr105='rm ~/Tools/grails && ln -s ~/Tools/grails-1.0.5 ~/Tools/grails'
alias gr111='rm ~/Tools/grails && ln -s ~/Tools/grails-1.1.1 ~/Tools/grails'
alias gr112='rm ~/Tools/grails && ln -s ~/Tools/grails-1.1.2 ~/Tools/grails'
alias gr12='rm ~/Tools/grails && ln -s ~/Tools/grails-1.2.0 ~/Tools/grails'
alias gr121='rm ~/Tools/grails && ln -s ~/Tools/grails-1.2.1 ~/Tools/grails'
alias gr122='rm ~/Tools/grails && ln -s ~/Tools/grails-1.2.2 ~/Tools/grails'
alias gr130rc1='rm ~/Tools/grails && ln -s ~/Tools/grails-1.3.0.RC1 ~/Tools/grails'
alias gr130rc2='rm ~/Tools/grails && ln -s ~/Tools/grails-1.3.0.RC2 ~/Tools/grails'
# use my local development copy of Grails
alias grdev='rm ~/Tools/grails && ln -s /Users/jeff/Projects/grails/core ~/Tools/grails'


Now if I want to use Grails 1.2.2 I just open a shell and type "gr122".

I use the exact same approach for other tools that I may want to easily move from version to version.

I do all of this on OS X. The same trick should work on Linux. I don't know enough about cygwin to know if this can work on Windows or not. I expect that it probably would.

That is all I have. It isn't any big deal but is one of those little things that over the years numerous folks have asked me about and then expressed that they liked it well enough that they were going to do the same.

Enjoy!

22 comments:

slippytoad said...

That's exactly what I do, I create a symlink called "grails-latest" as I'm usually moving to later versions.

James Carr said...

Good tip!

Al Rodgers said...

You could probably do the same on Windows using linkd from the Windows Server resource kit (you don't need to be running Windows Server).

Anonymous said...

Great post. The use of aliases is interesting. Why aliases and not just use a script?

I posted about a similar approach I use on Windows 7 here: http://wp.me/psHIY-5I

gocko said...

I also use this:
alias gc='grails clean'
alias gp='grails package'
alias gr='grails run-app'

Deluan said...

First I used an approach like this one, but then I created a shell script that do the selection automatically. If you want to take a look: http://github.com/deluan/grails.sh

Anonymous said...

Similar to Deluan's approach we also use automatic selection scripts.

Bash script to select Grails version automatically


.BAT file script for Windows to select Grails version automatically

Lauren Mendoza said...

Hi there, I don't know anything about Java or anything but I want to build a website with Groovy Grails. Can I do that? What is the best way to get started? Thanks

Unknown said...

Awesome technique!!!

Vigaplus natural erectile dysfunction supplement said...

"gr122" this key word is doesn't work .

hcg buy online said...

Great post. The use of aliases is interesting. HCG Blue Drops, the Faster and Natural way to lose weight...

Compare increase penis size pills said...

This process shows that how incredible way it is.I was got helped by this.

Vigaplus weak erection pills said...

This trick was sitting with another developer or during a live coding presentation at a conference without even thinking about it.

Anonymous said...

awesome technique worked like a charm for gr1.3.4 and gr2.0

Vizio M190VA Review said...

it good for us that is developed and bring to us this programs

Best premature ejaculation product said...

This is a great post over all, I loved the information it has provided.

GenFX best anti aging medicine said...

awesome technical work.the data you provided is really helpful.thanks for sharing such information.nice work for gr 1.1.2.

Best Vacuum Cleaners 2012 said...

I liked very much this article. Hope that your future posts will be better and better. Good luck man!

19PFL4505D/F7 said...

i really didn't get what you tried to explain here but i think it will be useful to others who know how to read it.thanks for sharing.

Research Paper spot said...

I want to make a website with wonderful Grails. Can I do that? What is the most excellent way to get started? Thanks

oracleR12 said...

Hi,
Awesome technical work.the data you provided is really helpful.thanks for sharing such a useful information.Good job keep posting on this kind of articles.
Thank you.
oracle R12 training

sdprdy said...
This comment has been removed by the author.