Thoughts about similar approach visited me as well because team, that I manage, works with various projects that use various versions of Grails. Practically, we regularly use versions 1.0.1, 1.0.2, 1.0.4 and custom 1.0.3-SNAPSHOT version of Grails 1.0.3 (really, we got some 1.0.3-SNAPSHOT version that really works better for us than final 1.0.3) and sometimes we are forced to do support for applications that uses older versions (0.5 and higher) or newer like 1.1.
Mainly team is working under Windows so script from blog is not very helpful for us. But as soon as additionally to management I like to do "small programming" (when have free time) so I dedicated some time of my Saturday evening (though better to say night) for creating of batch file that do similar to script from blog.
Below is the result tricky grails-env.cmd:
echo off
IF NOT "%1" == "" goto setVersion
set VERSION=1.1
goto prepareCmd
:setVersion
IF NOT "%1" == "1.0.3s" goto releaseVersion
set VERSION=1.0.3-SNAPSHOT-20080512
goto prepareCmd
:releaseVersion
IF NOT "%VERSION%" == "" goto prepareCmd
set VERSION=%1
:prepareCmd
set TMP_CMD=grails-env-changer.cmd
echo set GRAILS_HOME=%GRAILS_HOME%| sed -r s/grails-([0-9.])+/grails-%VERSION%/ > %TMP_CMD%
echo set PATH=%PATH%| sed -r s/grails-([0-9.])+/grails-%VERSION%/ >> %TMP_CMD%
call %TMP_CMD%
rem cleaning
rm %TMP_CMD%
set VERSION=
echo on
To get this working you need to place this .cmd file to some folder that is already defined in PATH variable. You should have UnxUtils installed and available in PATH (ports of common GNU utilities to native Win32). Different versions of Grails should be installed nearby. For example,
d:\java\grails-1.0.2etc
d:\java\grails-1.1
To call switching of environment to Grails 1.0.2 for active console you just need to run command:
grails-env 1.0.2
As soon as 1.1 is default environment so for switching back to Grails 1.1 will be enough to run command:
grails-env
Generally everything should be clean in script code. Though there are few tricks:
- Special handling of case for Grails 1.0.3-SNAPSHOT version that can be called by alias 1.0.3s
- Changing GRAILS_HOME and PATH environment variables through creating external .cmd file and calling it
I hope this script will help other Grails developers as well as developers working in our team. :)
Update: fixed expired link for zip file.