1

I have to manage multiple Grails version on Ubuntu, namely 1.3.9 and 2.0.4. I have installed Grails from the PPA, which allows to install multiple versions, but only creates one entry under bin, which points to the most recent version.

What is the simplest way to switch between Grails versions? Please note that I am new to Grails, and I would prefer a solution that does not depend on a particular IDE.

Andrea
  • 20,253
  • 23
  • 114
  • 183

7 Answers7

3

I use a script that parses the application.properties file to determine which version of Grails a particular app requires and then calls that. I install this script as "grails" in my bin directory. That way I can just run grails whatever and the correct version of Grails will be used automatically.

The script I use is one I hacked together myself, but there are similar (and better engineered) solutions such as https://github.com/deluan/grails.sh available to download.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
2

I wrote a simple script, is not as elaborate as Ian Roberts answer, but this works for me. I suppose that Grails versions are installed under /opt folder, also you need to add this file called grails to PATH.

#!/bin/bash

GRAILS_VERSION=`grep app.grails.version application.properties | cut -d'=' -f2`
GRAILS_HOME="/opt/grails-$GRAILS_VERSION"

export GRAILS_HOME
$GRAILS_HOME/bin/grails $*

There are more questions about this topic in Stack Overflow:

Community
  • 1
  • 1
Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73
2

Groovy enVironment Manager. http://gvmtool.net/ Best tool not only for grails, it works with groovy, griffon, gradle, vertx, etc.

AA.
  • 4,496
  • 31
  • 35
1

The easiest way is to specify the full path to the grails install you want to use instead of just relying on grails run-app. That way you have control over which version of "grails" is being executed.

I'm sure there are other more advanced ways to do it, but simply specifying the location of the grails executable is the easiest.

That said, working from within an IDE may make this easier or harder, but how you do so will depend on the specific IDE.

cdeszaq
  • 30,869
  • 25
  • 117
  • 173
  • 1
    You will also want to specify the grails.work.dir for the specific installation (-Dgrails.work.dir=THE_PATH) - though on second thought, you may not if you are using the default for that runtime... just keep this in mind. – cjstehno Jul 05 '12 at 17:24
1

I am using 7 grails version on my ubuntu machine . put the code below at the bottom of .bashrc file.

function switchGrails() {

echo “Switching to grails version: $1″

sudo rm /opt/grails

sudo ln -s /opt/$1 /opt/grails

echo “Done!”

}

alias grails225=’switchGrails “grails-2.2.5″‘

alias grails224=’switchGrails “grails-2.2.4″‘

alias grails223=’switchGrails “grails-2.2.3″‘

alias grails233=’switchGrails “grails-2.3.3″‘

alias grails235=’switchGrails “grails-2.3.5″‘

alias grails237=’switchGrails “grails-2.3.7″‘

alias grails2311=’switchGrails “grails-2.3.11″‘

After save and exit . Compile the .bashrc file . Type cd and . .bashrc to compile .bashrc file.

For more reference : https://pkashyap28.wordpress.com/2014/09/11/manage-multiple-grails-application-in-ubuntu/

Prabhat Kashyap
  • 986
  • 1
  • 7
  • 11
0

I create a bash script (grails.sh) placed inside the project to determine grails version and use the same version to compile/test/run the project.

#!/bin/bash

GRAILS_DIRECTORY="/usr/local"
GRAILS_VERSION=`grep app.grails.version application.properties | cut -d'=' -f2`
GRAILS_HOME="$GRAILS_DIRECTORY/grails-$GRAILS_VERSION"  
export GRAILS_HOME

$GRAILS_HOME/bin/grails compile
$GRAILS_HOME/bin/grails test-app
$GRAILS_HOME/bin/grails -Dserver.port=8443 run-app

To execute the bash script

$ bash grails.sh
prayagupa
  • 30,204
  • 14
  • 155
  • 192