What if you want to develop Grails 3 projects with Eclipse Mars (4.5) as easy as you did with Groovy/Grails Tool Suite or previous Eclipse versions? Written and tested with Eclipse Mars.1 Release (4.5.1, build 20150924-1200) and Grails 3.1.0 M1.

Eclipse Mars logo

The Eclipse landscape for Grails 3 development is a bit shady. Yes, the Getting Set Up in an IDE documentation of the currently latest version 3.1.0 M2 refers to Groovy/Grails Tool Suite as the recommended IDE for Eclipse users. However the latest GGTS to be downloaded from https://spring.io/tools/ggts is groovy-grails-tool-suite-3.6.4.RELEASE-e4.4.2-win32-x86_64.zip which is based on Eclipse Luna SR1 (4.4.2) — not Eclipse Mars.

Next to that, Groovy/Grails Tool Suite (GGTS) currently completely revolves around Grails 2 – all wizards to create taglibs, filters, controllers, services and domain classes don’t work anymore with Grails 3. Also the Grails dependency management, Grails command wizard and the rest aren’t functional anymore, since the Grails IDE plugin — which is the core component for all this — hasn’t been updated since Grails 3 came along.

Eclipse Mars was released last June and is the latest & greatest Eclipse version, so it’s no wonder you’ll be wanting to use this one as soon as possible. From the Mars website:

  • New Java IDE features, including hierarchical view of nested projects, ability to customize perspectives and speed improvements for text search.
  • Integrated tools for building and maintaining Docker containers, available from Linux Tools project.
  • Automated error reporting that allows Eclipse users to report errors directly to Eclipse projects.
  • and more…

The good news is that Eclipse Mars already comes with Gradle support — the Buildship Eclipse Plug-ins for Gradle can run all the tasks from your Grails 3 build.

So how do we make Eclipse Mars ready for Grails 3 development? In a nutshell: install Groovy support and cherry-pick some of the features of GGTS, like the GSP Editor 🙂

Installing plugins

I assume you already downloaded Eclipse Mars from https://www.eclipse.org/downloads/ for your platform. Any screenshots below are for Windows, but I have no doubt the instructions will be pretty similar for other platforms.

Install all plugins below before importing an existing project — which we’ll do later on.

Installing Groovy support

We need to install the Groovy Eclipse plugin in Eclipse. Since Grails source files are for the most part made up of Groovy files, we still need some assistance from the IDE when working with them. 

  1. In Eclipse, go to Help > Install New Software
  2. Use the update url http://dist.springsource.org/snapshot/GRECLIPSE/e4.5/ for Eclipse Mars (4.5.x).
  3. Select the
    Groovy Compiler 2.4 Feature and
    Groovy-Eclipse Feature.
    They both give us the Groovy support we need. Next.

    eclipse-install-groovy-2-4-feature
  4. Review the details. Next. Accept the terms. Next. It will install the software now.
  5. Restart Eclipse when asked.

Install Quick Text Search & GSP support

The .gsp (Groovy Server Pages) files are associated with a nice GSP Editor in GGTS, which would give syntax highlighting and auto-completion for Grails tags. In Eclipse Mars we get the default text editor; and I can tell you, that’s a pretty basic sight 🙂

So, the future of Groovy/Grails Tool Suite is uncertain – and their downloads are available for only a limited time.

ggts-pivotal-limited-time

What we can do is cherry-pick some of the hard work put into GGTS. That’s…

  • the Quick Text Search – Ctrl-Shift-L baby!
  • the GSP Editor. Unfortunately I haven’t found a way to Just Get The Editor, but we have to install the Grails IDE entirely for now. This gives us a bunch of stuff we cannot use anymore (such as wizards for Grails 2 artefacts, Grails 2 installations & launch configurations etc) — but most importantly it’ll give us the GSP Editor. Tag libraries won’t be recognized correctly, but syntax highlighting of GSP files is pretty handy.
  1. Download springsource-tool-suite-3.6.4.RELEASE-e4.5-updatesite.zip from https://spring.io/tools/ggts/all and save it locally.pivotal-update-site-archivesWhy not point to an update url directly if you want to install new software, are you asking? The ZIP archive still has the Grails IDE — in the update site this has been replaced with the Spring IDE.
  2. Select the
    Eclipse QuickSearch
    Grails IDE for Eclipseeclipse-install-quicksearch-and-grails-ide
  3. Restart Eclipse.

Basically, you could be done now. But while we’re at it, it’s always nice to…

Optionally, Install YAML support

Some of the configuration in a Grails 3 project is placed in application.yml – which is in YAML notation. To get better editor support for these kind of files, we still can of course still install the Spring IDE in Eclipse Mars, even through we previously installed the Grails IDE.

  1. In Eclipse, again go to Help > Install New Software
  2. Use the SpringSource Update Site for Eclipse 4.5 update url http://dist.springsource.com/release/TOOLS/update/e4.5/
  3. Select and install Spring IDE Coreeclipse-install-spring-ide
  4. Restart Eclipse.

Extensions .yml and .yaml are now loaded with Spring’s Yaml Properties Editor.

Finally

We can see by by the icons that the file associations are correctly set with their respective editors e.g. when opening the Open Resource window (Ctrl-Shift-R)

open-resource-file-associations-correct

Importing project

I assume you already created a Grails 3 project with e.g.

grails create-app helloworld

Eclipse Mars already comes with the Eclipse Buildship plugin. We need to use this plugin to “understand” our project with Gradle.

  1. Choose Import Gradle Project from the Package Explorer or File menu.
  2. “Import Gradle Project”. Select as Project Root directory: [some-dir]/helloworld. Next.
  3. “Import Options”. Select to use the Gradle wrapper (“Recommended”). Next.
  4. “Import Preview”. The project structure is checked. You might get a warning about Gradle 2.3 being used if you would import a default Grails 3.1 project. Finish.

The project should successfully be imported & visible in the Package Explorer. If you installed the Groovy-Eclipse plugin first, the project should correctly use the globally-set Groovy 2.4 compiler. No errors should be visible.

eclipse-imported-grails-gradle-project

Running the application

The Buildship plugin comes with a few views. From the Gradle Tasks view, expand your project to see all Gradle tasks.

eclipse-buildship-gradle-tasks

To run, double-click bootRun.

Although the focus immediately shifts to the Gradle Executions view for an overview of the executed Gradle tasks you won’t see much there with Gradle 2.3 – the wrapper used in a Grails 3.1 project. If you manually install a later Gradle version (e.g. 2.7) you can create new wrapper files in your project – so the Gradle Executions view can take advantage of this.

If you’ve started a Gradle task like this, it will also be available in the Run Configurations menu.

Stopping the application

Press the Stop button 🙂

It’ll take a few seconds – but then the application is stopped. You’ll notice the change in the icon state.

In conclusion

Eclipse Mars logoThat’s it. If you want to stick to Eclipse, Eclipse Mars is the best version you can get at the moment. It’s uncertain if Groovy/Grails Tool Suite will get any attention in the future or that the GSP Editor at least will find a way into it’s own project/plugin. Hopefully with above explanation you’ll be able to get up ‘n running for now with your Grails 3 projects in Eclipse Mars as you used to with Groovy/Grails Tool Suite and Grails 2. A new idea on my list at least is to automate all this with Eclipse Oomph if possible, but that’s for another time.

Any feedback is appreciated!