Grails 3 Released: Installing Gradle and Groovy 2.4 Support in Eclipse/GGTS

Grails 3 has been released with a ton of new features.

GGTS logoIf you’re used to adding a new Grails distribution in Eclipse or Groovy/Grails Tool Suite, you’ve might have experienced that your good old IDE might not support Grails 3 projects right out of the box.

You might be missing:

  • Grails 3 support at all 🙂
  • Gradle support
  • Groovy 2.4 support

Here’s how I think you can fix some of these things.

Grails 3 support

As you regularly do with new Grails distributions is to add it in GGTS under Preferences > Groovy > Grails. But dang!…it doesn’t recognize the grails-3.0.x-directory you just unzipped a minute ago.

GGTS doesn't recognize Grails 3

No worries! We have Gradle now.

Gradle is the new Grails 3 build system, in favor of Gant. If you’ve created e.g. the helloworld-application as used in the Getting Started section of the manual, you see a few files like build.gradle and gradle.properties.

Because of this we don’t need a specialized IDE plugin perse, since existing Gradle tooling can do the trick! So we skip adding a Grails 3 distribution and we look for…

Gradle support

It is possible that GGTS doesn’t know to import a Grails 3 project into your workspace, because of missing Gradle support. You can:

Generate Eclipse/GGTS…

  1. … files with gradlew eclipse.
  2. This will generate .project and .classpath which will allow you to “import it as an existing project” into your workspace

or install Gradle support

  1. Open Eclipse Marketplace, search for “gradle”
  2. Choose e.g. the Gradle IDE pack or just the Gradle Integration plugin
  3. Now you can find and import your project too

In GGTS your Grails 3 project is just a “regular” Gradle project.

Hello world!

The above screenshot is possibly an idealized view – it might as well that you have some red markers! I did.

Grails 3 comes with Groovy 2.4, and if you don’t have the correct version set, you get:

Groovy: compiler mismatch Project level is: 2.4 Workspace level is 2.3
Groovy compiler level expected by the project does not match workspace compiler level.

It’s similar as when you had to install Groovy 2.3 into GGTS 🙂 You can fix the project level to 2.3 but then you get

Groovy:Unexpected problem with AST transform: The Spock compiler plugin cannot execute because Spock 1.0.0-groovy-2.4 is not compatible with Groovy 2.3.10. For more information, see http://versioninfo.spockframework.org

You’ll have to get…

Groovy support

Assuming you don’t already have it, we have to install the Groovy Compiler 2.4 Feature into GGTS.

1. Go to Help > Install New Software and use the update site http://dist.springsource.org/snapshot/GRECLIPSE/e4.4/

2. Select the Groovy 2.4 compiler and Next.

GRECLIPSE update site

3. If there’s a conflict, just press on – it’ll install Groovy 2.4 next to the other versions.

GRECLIPSE update site - just continue!

4. Continue all the way. Finish, restart.

5. Switch the compiler for the workspace. Go to Preferences > Groovy > Compiler and switch to 2.4.3.

Switch to Groovy 2.4.3 compiler

Done.

Happy programming!

What Grails files should end up in version control?

You don’t need to add all files in a Grails application- or plugin project to version control, because some of the files are derived (this means they can be re-created from source files) or they are generated for you locally as developer (and have nothing to do with the team) if you use IDEs such as Eclipse or Groovy/Grails Tool Suite (GGTS).

You should ignore the following files in version control:

File or folder Why not in version control?
.project and .classpath Specific IDE (GGTS or Eclipse) generated derivations.
.settings Specific IDE (GGTS or Eclipse) derivations and/or user settings.
target Generated derived classes from sources
target-eclipse Specific IDE (GGTS or Eclipse) generated derived classes from sources

Generated files .project and .classpath contain developer-specific local paths which should not end up in version control. Former versions of Eclipse or GGTS could not deal with the absence of these files, and consequently failed to import any project without these.

Nowadays GGTS is able to detect this and fix it. You’ll get next dialog in this situation:

GGTS Convert to Grails project

By answering Yes, aforementioned files will be re-generated.

Grails 2.4 Released: Installing Groovy-Eclipse Compiler 2.3 in Eclipse/GGTS

GGTS logoThis month has been interesting: on the 7th Groovy 2.3.0 has been released, followed up by Grails 2.4 a few days ago. Great work!

UPDATE: GGTS 3.6.0 M1 has been released, which already includes support for Groovy 2.3.

If you’re an Eclipse or Groovy/Grails Tool Suite (GGTS) user, you might want to install the Groovy/Eclipse Compiler to have the IDE make use of all the Groovy 2.3 features. Now if you’ve downloaded the latest GGTS version – which at the moment is 3.5.1 – and created a brand new Grails 2.4 project, the Markers view might have alerted you to the following:

Groovy: compiler mismatch Project level is: 2.3 Workspace level is 2.1
Groovy compiler level expected by the project does not match workspace compiler level.

Consequently, also 1 Java problem is reported about a java.lang.NoSuchMethodError in an AssetMethodTagLib.groovy of the new Asset Pipeline Plugin shipping with Grails 2.4

You might be tempted to follow the Quick Fix and set the project to 2.3 but the settings screen doesn’t allow you to select 2.3 yet.

No Groovy 2.3 compiler

Fix it by installing the Groovy Compiler 2.3 for Groovy/Eclipse.

Installing the Groovy Compiler in GGTS

  1. Inside GGTS, on the Spring Dashboard go to Manage > IDE Extensions.
  2. Search for the keyword “groovy”, find the Groovy 2.3 Compiler for Groovy-Eclipse
  3. Select it and press Install. Restart when asked.

Installing the Groovy Compiler in GGTS (alternative) or Eclipse

  1. Inside GGTS/Eclipse, go to Help > Install New Software…
  2. Work with the snapshot Update Site of the Groovy/Eclipse project: http://dist.springsource.org/snapshot/GRECLIPSE/e4.3/
  3. Under Extra Groovy compilers (Optional) mark Groovy Compiler 2.3 Feature
  4. Install. Continue. Restart when asked.

After installation the compiler became the default for the entire workspace.

Groovy 2.3 installed

And you’re done. Problems are gone. Go work on your new Grails application 🙂