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.
How to use the compiler plugin---Setting up the POM
Here are the required additions to your maven project's pom.xml to use the compiler plugin. The artifacts are currently in the SpringSource snapshot maven repo. You must add it as a regular repository:
as well as a plugin repository:
And 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
This will allow Groovy files to be compiled. The maven-compiler-plugin prefers all source files to be in
src/test/java, but if you prefer you can use the standard Groovy convention and keep your files in
src/test/groovy. You can do so by adding the following plugin to your build section of the pom:
The information in this section was adapted from the Contraptions for Programming blog.
Sample project and source code
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:
The repository URL is:
There are several projects in the repository:
We don't have a maven archetype project available for the compiler plugin. We would greatly appreciate someone contributing one.
Groovy-Eclipse also provides integration with m2eclipse, the Eclipse's tool support for Maven. Using this integration will ensure that your GEM projects will be properly configured when they are imported into Eclipse. You can install the integration from the following update site:
Groovy-Eclipse m2eclipse integration:
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:
- 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.
- The Groovy-Eclipse compiler is the same inside Eclipse and inside Maven, and so configuration across the two platforms can be simplified.
- 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:
- Only one compiler level is supported. This is currently Groovy 1.7.5. If you require a different version of Groovy, then GMaven is your only option.
- GroovyDoc tool is not supported because the compiler plugin does not produce stubs.
- Groovy Mojos are not supported.
Whether or not the Groovy-Eclipse compiler plugin for Maven is appropriate for your project will depend on your requirements.