Resolving Grails version automatically on Windows
by Yuri Sakhno
A while ago we showed how it was possible to select automatically version of Grails to run just using a simple bash script. Trouble is, not all users use systems that recognize bash-scripts natively. One of such systems is, apparently, Windows platform. So today I’m going to show how it is possible to accomplish similar tasks on Windows using just the built-in functionality — the batch job processing files.
The bash script we showed earlier, used the knowledge embedded in the Grails-project file called application.properties to find out the version of Grails for the current project. Weirdly enough, batch files allow to do this as well (for the syntax used in properties file at least). Here is the snippet of code that does just that:
FOR /F "eol=# tokens=1,2 delims==" %%i IN (application.properties) DO ( IF "%%i" == "app.grails.version" ( SET GRAILS_VERSION=%%j ) ) SET GRAILS_HOME=%GRAILS_PREFIX%%GRAILS_VERSION% SET PATH=%GRAILS_HOME%\bin CALL %GRAILS_HOME%\bin\grails.bat %*