How do you manage developing with multiple versions of Grails using Windows?
Asked Answered
U

10

16

We've been using Grails for a little while now and have been through a few Grails versions now. We don't always want to migrate our 'older' apps immediately but often use a newer version for new development. Changing the Windows environment variables is inconvenient since I sometimes have to work on two related projects at the same time that are running different versions of Grails.

In Linux, I'd probably create wrapper scripts or aliases to allow me to specify on the command line a version switch but I don't believe Grails supports this.

How are others that need to code against multiple versions of Grails managing it?

Update:
I created a gv.bat file to set the GRAILS\_HOME and PATH environment variables. I added a GRAILS\_INSTALLS environment variable (c:\usr\local\grails on my box) and removed the %GRAILS_HOME%\bin reference from my PATH.

gv.bat

@echo off
SET GRAILS_HOME=%GRAILS_INSTALLS%\grails-%1
SET PATH=%GRAILS_HOME%\bin;%PATH%

To do any Grails work I run > gv 1.1.2 or whatever version I need to work with. I'd like to figure out how to do a string replace in the PATH to change the value but that turned out to be difficult for me

Unaffected answered 24/11, 2009 at 17:15 Comment(0)
S
3

It's now MUCH much later, and GVM is not the tool it once was. Instead, I use SDKMAN (https://sdkman.io/) and, with Windows getting some linux-like tooling, or using Cygwin, etc. it's installable on Windows.

------ OLD answer below ------

GVM is a tool for unix/mac environments to manage Groovy/Gradle/Grails/more versions, and someone finally made a Windows equivalent called Posh-gvm (short for Power-shell GVM). It's very useful and easy to use to download and configure your environment for whichever version of these tools you want to use at any point in time.

If you're using an IDE, posh-gvm is still a great way to download/install the new versions as they come out, and your IDE can point into the posh-gvm install directories.

Sunstone answered 15/12, 2014 at 3:13 Comment(3)
I'm no longer developing on Windows but this is definitely good to know.Unaffected
I could not figure out how to install posh-gvm. The website documenation says to install by typing "Install-Package posh-gvm", but this just gives "no match was found"Preposterous
Also tried the "Via short script" method, which gives "SecurityError: (:) [Import-Module], PSSecurityException" when you execute "Import-Module posh-gvm", even running as administrator. Tried both 32 and 64 bit versions of powershell, no luck installing this thing.Preposterous
R
10

I have a couple of bat files which changes the GRAILS_HOME and the system PATH according to which version I'm using.

It's not the most beautifull solution at all, but at least works for me.

Roxie answered 24/11, 2009 at 17:17 Comment(1)
Are they long, would you mind posting the one that updates the PATH variable?Unaffected
P
6

I have a batch file, that looks like below.

@ECHO OFF

if "%1"=="231" goto grails231
if "%1"=="232" goto grails232
if "%1"=="233" goto grails233
if "%1"=="234" goto grails234


goto end

:grails231
set GRAILS_HOME=F:\softwares\grails-2.3.1
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end

:grails232
set GRAILS_HOME=F:\softwares\grails-2.3.2
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end


:grails233
set GRAILS_HOME=F:\softwares\grails-2.3.3
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end

:grails234
set GRAILS_HOME=F:\softwares\grails-2.3.4
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end

:end

It can be run like 'setgrails 233' and it will set the grails 2.3.3

Pincushion answered 22/1, 2014 at 4:13 Comment(0)
S
4

IntelliJ allows you to specify which version of Grails to apply as a per-project facet configuration. The Eclipse plugin has yet to achieve this level of abstraction.

Sunstone answered 24/11, 2009 at 19:56 Comment(2)
The new Eclipse plugin does in fact allow you to set which grails version to use on a per-project basis. Or at least the new springsource version of the plugin does.Spikes
Can you cite a source? I've heard they were working on allowing it, but that configuring GROOVY version had to come first.Sunstone
W
3

I have the same issue as you. For my concern, I have written a batch script (grails_version.bat) accessible from my Windows PATH home.

Set up your GRAILS_HOME to your standard Grails version and each time you want to run a Grails app into another version than the standard one, open a command prompt, run the batch script (>grails_version) and run your grails commands (ex: grails run-app).

If your are using IntelliJ, you can configure the grails version per application.

Here is the code:

@echo off

set v11=1.1
set v111=1.1.1
set v12M2=1.2-M2
set v12M3=1.2-M3
set v12M4=1.2-M4
set /p grails_version= What is the grails version (%v11%, %v111%, %v12M2%, %v12M3% (default), %v12M4%)?
if "%grails_version%" == "%v11%" goto :set_grails_home 
if "%grails_version%" == "%v111%" goto :set_grails_home 
if "%grails_version%" == "%v12M2%" goto :set_grails_home 
if "%grails_version%" == "%v12M3%" goto :set_grails_home 
if "%grails_version%" == "%v12M4%" goto :set_grails_home 
if "%grails_version%" == "" goto :set_grails_home_default 

:no_valid_input
echo The input version is not valid
exit

:set_grails_home_default
set grails_version=%v12M3%

:set_grails_home
set GRAILS_HOME=D:\Install\grails\grails-%grails_version%
path = %GRAILS_HOME%\bin;%PATH%
echo GRAILS_HOME=%GRAILS_HOME%

Enjoy.

Whitefly answered 25/11, 2009 at 0:21 Comment(0)
S
3

It's now MUCH much later, and GVM is not the tool it once was. Instead, I use SDKMAN (https://sdkman.io/) and, with Windows getting some linux-like tooling, or using Cygwin, etc. it's installable on Windows.

------ OLD answer below ------

GVM is a tool for unix/mac environments to manage Groovy/Gradle/Grails/more versions, and someone finally made a Windows equivalent called Posh-gvm (short for Power-shell GVM). It's very useful and easy to use to download and configure your environment for whichever version of these tools you want to use at any point in time.

If you're using an IDE, posh-gvm is still a great way to download/install the new versions as they come out, and your IDE can point into the posh-gvm install directories.

Sunstone answered 15/12, 2014 at 3:13 Comment(3)
I'm no longer developing on Windows but this is definitely good to know.Unaffected
I could not figure out how to install posh-gvm. The website documenation says to install by typing "Install-Package posh-gvm", but this just gives "no match was found"Preposterous
Also tried the "Via short script" method, which gives "SecurityError: (:) [Import-Module], PSSecurityException" when you execute "Import-Module posh-gvm", even running as administrator. Tried both 32 and 64 bit versions of powershell, no luck installing this thing.Preposterous
T
2

I do that in Windows as below.

enter image description here

enter image description here

So I just change GRAILS_VER environment variable. I can change my grails version anytime.

enter image description here

Thimbleful answered 22/11, 2016 at 5:48 Comment(0)
Q
1

On Linux/Mac, GVM is a fantastic tool for installing and working with multiple versions of Grails, Groovy, etc. You can't use GVM itself on Windows1, but there is a clone posh-gvm that will run under Powershell on Windows.

  1. AFAIK this is because Windows doesn't support symlinks
Querulous answered 24/7, 2014 at 15:48 Comment(0)
L
1

The thing I would change about these answers is the PATH handling. Each time you run the script and change versions, you will extend your path one more node. It works, but messy. Try creating a $path2 with no reference to your JAVA_HOME or GRAILS_HOME and the path become path2+grails+java. Example: set PATH="%PATH2%;F:\softwares\grails-2.3.1;path2java7.

The only reason I add the Java7 reference is that I need Java 6 for my older grails app and Java 7 for newer grails.

Lenrow answered 25/7, 2014 at 17:22 Comment(0)
C
0

Check out this link, it explains exactly how to do that using cygwin and mapping several aliases.

Also, learn how the plugins directory work and replicate it several times for each version of Grails. I also use global plugins for the ones I use often, like tomcat, hibernate, dbUtil, console, etc.

Say you want to switch between 1.1 and 1.2M4 - you could have those directories setup with the plugins you are using:

c:\Users\username\.grails\1.2-M4\projects\projectname\plugins

c:\Users\username\.grails\1.1.1\projects\projectname\plugins

Then, take applications.groovy and make several copies, like

application.groovy.1.1
application.groovy.1.2M4

Now, to switch, you just need to rename the application.groovy.X to application.groovy and you are good to go (after running grails clean of course):

grails1.1 run-app 
grails12M4 run-app

Lastly, there are other differences between versions (i.e. new 1.2 is introducing dependencies DSL), but most of the time things are backwards compatible enough that you can come up with a common denominator.

Covert answered 24/11, 2009 at 21:42 Comment(0)
M
0

Some answers are outdated.

Seems that the best option nowadays is SDKMAN!:

SDKMAN! installs smoothly on Mac OSX, Linux, WLS, Cygwin, Solaris and FreeBSD. We also support Bash and ZSH shells.

Is also possible to install on Windows, but SDKMAN "can not be installed natively on Windows and requires WLS, Cygwin or MSYS+MinGW".

After that, you can choose the Grails SDK and which version you want. For example:

sdk install grails 1.3.7
Maharanee answered 18/2, 2020 at 11:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.