Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 15 Next »

Groovy-Eclipse provides a compiler plugin for Maven. Using the compiler plugin, it is possible to compile your maven projects using the Groovy-Eclipse compiler.

Icon

The most recent version of the Groovy-Eclipse-Compiler plugin for maven is 2.5.1-1.

How to use the compiler plugin---Setting up the POM

In your plugin section, you must change the compiler used by the maven-compiler-plugin. Like the javac ant task, the maven-compiler-plugin does not actually compile, but rather delegates the compilation to a different artifact (in our case, the groovy-eclipse-batch artifact):

By default, this will use Groovy 1.8.0 to compile your code. If you would prefer to use 1.7.10, then add another dependency to the maven-compiler-plugin:

This will allow Groovy files to be compiled. The maven-compiler-plugin prefers all source files to be in src/main/java and src/test/java, but if you prefer you can use the standard Groovy convention and keep your files in src/main/groovy and src/test/groovy. You can do so by adding the following plugin to your build section of the pom:

The groovy-eclipse-compiler recognizes all settings supported by the maven-compiler-plugin.

Note that the groovy-eclipse-compiler and groovy-eclipse-batch artifacts are now available in Maven-central, so there is no longer any need to explicitly declare any extra repositories.

Sample project and source code

There is an archetype available for this project. You can use it through a command like this:

A sample project using the compiler plugin as well as the source code for the plugin itself are available from the Codehaus.org subversion repository:

Icon

The SVN repository URL is:

https://svn.codehaus.org/groovy/eclipse/trunk/extras

There are several projects in the repository:

  • groovy-eclipse-compiler : the compiler plugin itself (an m2eclipse project).
  • groovy-eclipse-batch-builder : a set of ant scripts and configuration files used to build the groovy-eclipse-batch artifact. This artifact is an amalgamation of all jars required for compiling Groovy and Java code in Eclipse, including ecj (the Eclipse compiler for Java), the non-UI components of Groovy-Eclipse, the Groovy jars, and various required Eclipse bundles.
  • groovy-eclipse-maven-tests : a sample project that uses the compiler plugin (an m2eclipse project).
  • org.codehaus.groovy.m2eclipse : an Eclipse plugin that provides integration between Groovy-Eclipse and m2eclipse (the Maven tooling for Eclipse).
  • Feature org.codehaus.groovy.m2eclipse : an Eclipse feature that is required for building and releasing the org.codehaus.groovy.m2eclipse plugin.

Why another Groovy compiler for Maven? What about GMaven?

There are several benefits that the compiler plugin provides over GMaven, but at the same time it has a few limitations. First, the benefits:

  1. The compiler plugin does not require the creation of Java stubs so that your Groovy files can compile against Java files. This will prevent some arcane compile errors from appearing.
  2. The Groovy-Eclipse compiler is the same inside Eclipse and inside Maven, and so configuration across the two platforms can be simplified.
  3. The compiler plugin is a standard compiler plugin for Maven. It therefore follows all allows all the same standard configuration that the Javac compiler plugin uses. This makes it simpler to introduce Groovy into an existing Maven project. All you need to do is change the compiler plugin that the pom references.

There are some limitations:

  1. GroovyDoc tool is not supported because the compiler plugin does not produce stubs.
  2. Groovy Mojos are not supported.
  3. Groovy scripts cannot be executed in your poms.
  4. Groovy compiler options are not passed through to the compiler.
  5. The defaultScriptExtension compiler option is not supported.

Whether or not the Groovy-Eclipse compiler plugin for Maven is appropriate for your project will depend on your requirements.

M2Eclipse integration

Groovy-Eclipse also provides integration with m2eclipse, the Eclipse's tool support for Maven. Currently, this support is only meant to be used with existing GMaven projects. It will have no effect on groovy-eclipse-compiler projects. If you want to use groovy-eclipse-compiler projects in maven, then you should use the maven-eclipse-plugin as described above.

Using this integration will ensure that your GMaven projects will be properly configured when they are imported into Eclipse. You can install the integration from the following update site:

Where to find more information and ask questions

Icon

Please ask all questions on the Groovy-Eclipse mailing list. Any bugs or feature enhancements should go on Groovy-Eclipse's jira.

The compiler plugin was originally described here and here, but these posts are no longer updated and this page will always contain the more recent information.

  • No labels