My preferred tool for doing Grails development is the SpringSource Tool Suite (STS), which is built on the free Eclipse IDE that you download with a number of plugins already installed. It is totally free and has a number of nice features you do not get with a simple text editor.
Why should you use STS? Since STS is built on Eclipse, you get a number of nice features built in. Here are just a couple of my favorites:
And many more:
- Auto formatting of files including fixing indents and spacing
- Highly configurable workspace (tabbed editing, split-pane editing, task lists, etc)
- Huge Plugin community (source control, other languages, etc)
Assuming you are already doing grails development, installation is very straight-forward. Follow the instructions on the grails.org site here: http://grails.org/STS+Integration
If you are starting from scratch, you will have to install Java and probably specific versions of Grails before you can install STS.
Out of the box, STS is geared towards Spring development. Since Grails runs on top of Spring, after you install STS you have to install a couple plugins for Groovy and Grails. It is all detailed in the grails.org post. Assuming you already have Grails installed on your computer, you do not need to install the Grails language extension. You will just need the Grails and Groovy “tooling extensions.”
Once STS is installed and open, here are a couple of things to get started.
First, setup your Grails installations if you did not do that during the installation. Go to the Preferences (MacOS: SpringSource Tool Suite > Preferences, Windows/Linux: Window > Preferences) and then navigate to Groovy > Grails. Just browse to your grails directory and STS will fill in all the details for you. You can do this for as many versions of Grails as you want. The default will be used for new projects, but you can always specify which version to use for a specific project.
Importing Existing Project
To pull your existing Grails project into STS, just follow these steps
- File > New… > Grails Project
- Under Contents, change it to “Use External Location” and Browse to your existing Grails project
First, you could get a “Incompatible Groovy Compiler Version” warning
In my case I was importing a Grails 1.3.7 project and my Groovy version was 1.8.6, which is more recent than Grails 1.3.7 uses. Most of the time I just ignore this message because I do not have any problems with using so-called “incompatible” versions. However, you can easily switch to a different version of Groovy if needed. Go to the Preferences > Groovy > Compiler. In here is a button to switch versions of Groovy and a link with more details.
Second, you could get a “Grails version mismatch detected” warning
In my case, the default Grails in STS was 2.0.3 and my project was 1.3.7. If you say “Yes” it will run “grails upgrade” on your project. If you say “No” it will configure you project to use the correct version, 1.3.7 in my case. You can see what version of Grails is configured for a project by right-clicking (control-click on a Mac) on the project name and choosing Properties then Grails.
Third, you could get a “Grails version x.x.x not installed” warning
As you can guess, this means the version of Grails specified by your project is not installed in Grails. You can either upgrade your project through STS (clicking Yes) or go back and configure STS to use that version of Grails.
Features of STS with Grails
Running Grails Commands:
Built into STS is the ability to run any Grails command, just like you would from the command line. Some are tightly integrated and others not so much. For example, you can do File > New > Domain Class (or Controller, or Service, etc) which will run “grails create-domain-class MyDomain” automatically.
You can also run any other Grails command with the “Grails Command” button in the toolbar:
This will bring up a prompt and you can enter any command:
If you enter run-app like I did, it will bring up a server within STS and you can click on the URL in the console view. That said, I typically still run the application from the command line out of habit.
You can still run commands from the command line. Just remember to refresh your project in STS if you are creating any new files.
Note on Source Control
Using STS will create a new target-eclipse directory in your project and may put some items in the .settings directory. You will probably want to exclude these from your source control (using .gitignore or similiar)