Grails + IntelliJ Setup on OS X

The following is a set of instructions for setting up your Grails development environment on OS X Leopard. This is probably not of much use to anyone else, but at least I’ll have it captured for myself.

Download & Setup Groovy

You’ll need to grab the latest version of Groovy here (1.5.4 at the time of writing). Once you extract the zip file (Safari probably did that for you), move the extracted Groovy folder to the /usr/local folder. Here’s the command I used from a terminal window (you’ll probably be prompted for your password):

sudo mv groovy-1.5.4/ /usr/local/

You’ll need to make sure that the JAVA_HOME environment variable is set. You can add this to your .profile file if it’s not already there. I use TextMate as my editor of choice so I issued this command in the terminal window:

mate ~/.profile

Once you have that file open, add the following line:

export JAVA_HOME=/Library/Java/Home

While editing your .profile file you also need to add the GROOVY_HOME environment variable:

export GROOVY_HOME=/usr/local/groovy-1.5.4

In your .profile file you also need to add $GROOVY_HOME/bin to your PATH. So the last line in your .profile file should look something like this:

export PATH=$GROOVY_HOME/bin:$PATH

At this point you need to execute your .profile file to pick up your latest changes. You can do that with the following command:

. ~/.profile

You should be able to test your Groovy install by running the following command:

groovy -version

It should report something like this:

Groovy Version: 1.5.4 JVM: 1.5.0_13-119

Download & Setup Grails

Download the latest version of Grails here (1.0.2 as of this writing). Once you extract the zip file (or tar.gz), move the extracted Grails folder to the /usr/local folder:

sudo mv grails-1.0.2/ /usr/local/

Edit your .profile file again adding the GRAILS_HOME environment variable:

export GRAILS_HOME=/usr/local/grails-1.0.2

Add $GRAILS_HOME/bin to your PATH. The last line of your .profile file should now look something like:

export PATH=$GROOVY_HOME/bin:$GRAILS_HOME/bin:$PATH

Execute your .profile file to pick up your changes:

. ~/.profile

At this point you should have a working Grails setup. You can test it out using the following command:

grails

If everything is working you should get a help message similar to the following:

Welcome to Grails 1.0.2 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/local/grails-1.0.2

No script name specified. Use 'grails help' for more info

The Grails installation notes mention the possibly of needing to issue a chmod +X on the grails executable, but I didn’t find this to be necessary. You’re mileage may vary. If you do run into errors you may want to check out the Grails install page. In that case, you may just want to bale on this blog altogether and go somewhere else.

You could stop at this point if you just wanted to kick it old school and use a text editor to write code, but we shall press on.

Install Intellij IDEA Plugin

From inside IntelliJ you’ll need to grab the latest version of the JetGroovy plugin (1.5.15312). Once you install the plugin you’ll have to restart IntelliJ for the changes to take effect. You’ll need to tell the JetGroovy plugin where to find Groovy & Grails. Unfortunately the plugin seems unable to use the environment variables. To set these values Select “Groovy & Grails” under “Settings” and enter the proper path values.

At this point you should be able to create a new project within IntelliJ with a “Grails Application” module.

When you create the new project IntelliJ will run all of the necessary commands to properly setup your new Grails app. Once created you should be able to create a new “Grails Application” “Run Configuration” for your application and your off to the races.

My work here is done.

2 Responses to “Grails + IntelliJ Setup on OS X”

  1. MPS Says:

    Nicely done, thanks! I did have to do a “chmod a+x *” in /usr/local/grails-1.0.2/bin, FWIW.

  2. Jared Peterson Says:

    Thanks Michael, I updated the IntelliJ section to include setting the paths for Groovy & Grails.

Leave a Reply