Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Change recommend maven-compiler plugin version to 3.1 seems to work better

...

Info

The most recent version of the Groovy-Eclipse-Compiler plugin for maven is 2.78.0-01.
2.79.10-01-SNAPSHOT is now available from http://nexus.codehaus.org/snapshots/.

The most recent version of the groovy-eclipse-batch artifact is 2.1.8-01 (for Groovy 2.1) and 2.0.7-03 (for Groovy 2.0). They are both available from maven central.

 

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

...

Code Block
languagehtml/xml
<build>
...
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2<<!-- 2.8.0-01 and later require maven-compiler-plugin 3.1 or higher -->
    <version>3.1</version>
    <configuration>
      <compilerId>groovy-eclipse-compiler</compilerId>
      <!-- set verbose to be true if you want lots of uninteresting messages -->
      <!-- <verbose>true</verbose> -->
    </configuration>
    <dependencies>
      <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-eclipse-compiler</artifactId>
        <version>2.78.0-01</version>
      </dependency>
    </dependencies>   </plugin>!-- for  2.8..
</plugins>
</build>

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

Code Block
languagehtml/xml
<dependency>
  0-01 and later you must have an explicit dependency on groovy-eclipse-batch -->
      <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-eclipse-batch</artifactId>
        <version>2.1.8-01</version>
        <!-- or choose a different compiler version -->
        <!-- <version>1.8.6-01</version> -->
        <!-- <version>1.7.10-06</version> -->
</dependency>
 </dependencies>
  </plugin>
  ...
</plugins>
</build>

This will allow Groovy files to be compiled. The groovy-eclipse-compiler recognizes all settings supported by the maven-compiler-plugin.

...

Code Block
languagehtml/xml
<dependencies>
  ...
  <dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>1<version>2.81.6<8</version>
  </dependency>
  ...
</dependencies>

 

 

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

...

Code Block
languagehtml/xml
<build>
  ...
  <plugin>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-eclipse-compiler</artifactId>
    <version>2.78.0-01</version>
    <extensions>true</extensions>
  </plugin>
  ...
</build>

...

Code Block
languagebash
mvn archetype:generate \
    -DarchetypeGroupId=org.codehaus.groovy \
    -DarchetypeArtifactId=groovy-eclipse-quickstart \
    -DarchetypeVersion=2.5.2-01 \
    -DgroupId=foo \
    -DartifactId=bar \
    -Dversion=1 \
    -DinteractiveMode=false \
    -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/snapshots/

(This archetype is not actively maintained.)

A sample project using the compiler plugin as well as the source code for the plugin itself are available from the github repository:

...

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 benefitsGMaven 2.0 and later no longer supports compilation.  You can read more about this on the GMaven 2 project page. GMaven 1.x is now deprecated.

GMaven 1.x had limitations over the groovy-eclipse-compiler and for the following reasons GMaven 2.0 compilation is no longer supported:

  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 still some limitationsreasons to use GMaven:

  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.

...

Code Block
languagehtml/xml
<configuration>
  <compilerId>groovy-eclipse-compiler</compilerId>
  <verbose>true</verbose>
  <compilerArguments>
    <javaAgentClass>lombok.core.Agent</javaAgentClass>
  </compilerArguments>
  <fork>true</fork>
</configuration>

 

Groovy-Eclipse configurator for m2Eclipse

If you are going to be working with your maven project inside of Eclipse, it is strongly recommended that you use m2eclipse. And to use your Groovy projects with m2eclipse, you will need to install the Groovy-Eclipse configurator for m2eclipse. This feature is available any of the Groovy-Eclipse update sites (e.g., nightly, milestone, or release). Just go to your Eclipse update manager and add the Groovy-Eclipse update sites (if you haven't done so already). Select the Groovy-Eclipse M2E integration.

Release Builds

Development Builds

Eclipse levelDevelopment update site
4.2 (Juno)http://dist.codehausspringsource.org/groovysnapshot/distributionsGRECLIPSE/greclipse/snapshot/e4.2/
3.7 (Indigo)http://dist.codehausspringsource.org/groovysnapshot/distributionsGRECLIPSE/greclipse/snapshot/e3.7

The Groovy-Eclipse configurator for m2eclipse is not compatible with AspectJ or Scala.  So you cannot use a joint AspectJ/Scala/Groovy project in Eclipse. These languages must be separated into separate sub-projects.

Where to find more information and ask questions

...