Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>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.</p><p><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e3RvY30&locale=en_GB&version=2" data-macro-name="toc"></p><table class="wysiwyg-macro" data-macro-name="info" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2luZm99&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>The most recent version of the Groovy-Eclipse-Compiler plugin for maven is <strong>2.7.1-01</strong>.<br /><strong>2.7.2-01-SNAPSHOT</strong> is now available from <a href="http://nexus.codehaus.org/snapshots/">http://nexus.codehaus.org/snapshots/</a>.</p><p>The most recent version of the groovy-eclipse-batch artifact is 2.1.3-01. This is available from maven central.</p><p> </p></td></tr></table><h3>How to use the compiler plugin---Setting up the POM</h3><p>In your plugin section, you must change the compiler used by the <a href="http://maven.apache.org/plugins/maven-compiler-plugin/">maven-compiler-plugin</a>. Like the <a href="http://ant.apache.org/manual/Tasks/javac.html">javac ant task</a>, the maven-compiler-plugin does not actually compile, but rather delegates the compilation to a different artifact (in our case, the <code>groovy-eclipse-batch</code> artifact):</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=html/xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9aHRtbC94bWx9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><build> ... <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</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.7.0-01</version> </dependency> </dependencies> </plugin> ... </plugins> </build> </pre></td></tr></table><p>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:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=html/xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9aHRtbC94bWx9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-batch</artifactId> <version>1.8.6-01</version> <!-- <version>1.7.10-06</version> --> </dependency> </pre></td></tr></table><p>This will allow Groovy files to be compiled. The groovy-eclipse-compiler recognizes all settings supported by the <a href="http://maven.apache.org/plugins/maven-compiler-plugin/">maven-compiler-plugin</a>.</p><p>Remember that you still need to specify a groovy artifact as a build dependency in addition to the <code>maven-compiler-plugin</code> dependency. The groovy dependency version should match the compiler version. Something like this:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=html/xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9aHRtbC94bWx9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><dependencies> ... <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>1.8.6</version> </dependency> ... </dependencies></pre></td></tr></table><p> </p><p> </p><p>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.</p><h3>Setting up the source folders</h3><p>There are several ways to set up your maven project to recognize Groovy source files</p><h4>Do nothing</h4><p>The simplest way to set up your source folders is to do nothing at all: add all of your Groovy files to <code>src/main/java</code> and <code>src/test/java</code>. This requires absolutely no extra configuration and is easy to implement. However, this is not a standard maven approach to setting up your project. If you require a more standard maven approach, then it is possible to put your Groovy files in <code>src/main/groovy</code> and <code>src/test/groovy</code> and you Java files in <code>src/main/java</code> and <code>src/test/java</code>. There are several ways of doing this.</p><h4>Do almost nothing</h4><p>If there is <em>at least one</em> file (Java or not) in <code>src/main/java</code>, then all files in <code>src/main/groovy</code> will be found. If, however, <code>src/main/java</code> is empty, then <code>src/main/groovy</code> will be ignored. You can get around this by placing an empty file in <code>src/main/java</code> just so that <code>src/main/groovy</code> will be recognized. The same is true for <code>src/test/java</code> and <code>src/test/groovy</code>. This is actually a workaround for <a href="http://jira.codehaus.org/browse/GRECLIPSE-1221">GRECLIPSE-1221</a>.</p><h4>Use the <code>groovy-eclipse-compiler</code> mojo for configuring source folders</h4><p>(You only need this approach if your project has an empty <code>src/main/java</code> or <code>src/test/java</code>.)</p><p>If your project has no Java files and you don't want to add an empty file in <code>src/main/java</code>, then you can configure source files by referencing the groovy-eclipse-compiler mojo. Just add this to the <code>plugins</code> section of your pom:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=html/xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9aHRtbC94bWx9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><build> ... <plugin> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.7.0-01</version> <extensions>true</extensions> </plugin> ... </build> </pre></td></tr></table><p>The <code><extensions>true</extensions></code> section is important because this redefines the default lifecycle of your project so that an extra phase is added. This phase has an extra goal attached to it that adds the two Groovy source folders.</p><h4>Use the <code>build-helper-maven-plugin</code></h4><p>(You only need this approach if your project has an empty <code>src/main/java</code> or <code>src/test/java</code>.)</p><p>The <code>build-helper-maven-plugin</code> allows you to do things like adding extra source folders to your project without needing to redefine the default lifecycle. You need to add this configuration to your build plugin section:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=html/xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9aHRtbC94bWx9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><build> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.5</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/main/groovy</source> </sources> </configuration> </execution> <execution> <id>add-test-source</id> <phase>generate-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/test/groovy</source> </sources> </configuration> </execution> </executions> </plugin> ... </build> </pre></td></tr></table><p>The benefit of using this approach is that you do not need to make any changes to the default lifecycle. The downside is, of course, that you need 31 lines of configuration to do this!</p><h3>Sample project and source code</h3><p>There is an archetype available for this project. You can use it through a command like this:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=bash" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9YmFzaH0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>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/ </pre></td></tr></table><p>A <a href="https://svn.codehaus.org/groovy/eclipse/trunk/extras/groovy-eclipse-maven-tests">sample project</a> using the compiler plugin as well as the source code for the plugin itself are available from the <a href="https://github.com/groovy/groovy-eclipse/">github repository</a>:</p><table class="wysiwyg-macro" data-macro-name="info" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2luZm99&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>The full URL to the maven projects is:</p><p><code><a href="https://github.com/groovy/groovy-eclipse/tree/master/extras">https://github.com/groovy/groovy-eclipse/tree/master/extras</a><br /></code></p><p>There are several projects in the repository:</p><ul><li><code>groovy-eclipse-compiler</code> : the compiler plugin itself (an m2eclipse project).</li><li><code>groovy-eclipse-batch-builder</code> : a set of ant scripts and configuration files used to build the <code>groovy-eclipse-batch</code> 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.</li><li><code>groovy-eclipse-maven-tests</code> : a sample project that uses the compiler plugin (an m2eclipse project).</li><li><code>org.codehaus.groovy.m2eclipse</code> : an Eclipse plugin that provides integration between Groovy-Eclipse and m2eclipse (the Maven tooling for Eclipse).</li><li><code>Feature org.codehaus.groovy.m2eclipse</code> : an Eclipse feature that is required for building and releasing the <code>org.codehaus.groovy.m2eclipse</code> plugin.</li></ul></td></tr></table><p>The sample project and archetype is not maintained as well as we would like. Some community help with this would be greatly appreciated. Please see <a href="http://jira.codehaus.org/browse/GRECLIPSE-1285">GRECLIPSE-1285</a>.</p><h3>Why another Groovy compiler for Maven? What about GMaven?</h3><p>There are several benefits that the compiler plugin provides over GMaven, but at the same time it has a few limitations. First, the benefits:</p><ol><li>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.</li><li>The Groovy-Eclipse compiler is the same inside Eclipse and inside Maven, and so configuration across the two platforms can be simplified.</li><li>The compiler plugin is a <a href="http://maven.apache.org/plugins/maven-compiler-plugin/non-javac-compilers.html">standard compiler plugin</a> 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.</li></ol><p>There are some limitations:</p><ol><li>GroovyDoc tool is not supported because the compiler plugin does not produce stubs.</li><li>Groovy Mojos are not supported.</li><li>Groovy scripts cannot be executed in your poms.</li><li>Groovy compiler options are not passed through to the compiler.</li><li>The <code>defaultScriptExtension</code> compiler option is not supported.</li></ol><p>Whether or not the Groovy-Eclipse compiler plugin for Maven is appropriate for your project will depend on your requirements.</p><h3>Project Lombok</h3><p><a href="http://projectlombok.org/">Project Lombok</a> is compatible with the groovy-eclipse-compiler. There is some extra configuration that you need to do. The lombok jar needs to be added to <em>both the build and compile dependencies sections</em>:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=html/xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9aHRtbC94bWx9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>0.10.4</version> </dependency></pre></td></tr></table><p>Also, the following configuration needs to be added to the maven-compiler-plugin configuration:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=html/xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9aHRtbC94bWx9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><configuration> <compilerId>groovy-eclipse-compiler</compilerId> <verbose>true</verbose> <compilerArguments> <javaAgentClass>lombok.core.Agent</javaAgentClass> </compilerArguments> <fork>true</fork> </configuration></pre></td></tr></table><h3>Groovy-Eclipse configurator for m2Eclipse</h3><p>If you are going to be working with your maven project inside of Eclipse, it is strongly recommended that you use <a href="http://eclipse.org/m2e">m2eclipse</a>. 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 <em>Groovy-Eclipse M2E integration</em>.</p><h2>Release Builds</h2><table class="confluenceTable"><tbody><tr><th class="confluenceTh">Eclipse level</th><th class="confluenceTh">Release update site</th></tr><tr><td class="confluenceTd">4.2 (Juno)</td><td class="confluenceTd"><code><a href="http://dist.springsource.org/release/GRECLIPSE/e4.2">http://dist.springsource.org/release/GRECLIPSE/e4.2</a></code></td></tr><tr><td class="confluenceTd">3.7 (Indigo)</td><td class="confluenceTd"><code><code><a href="http://dist.springsource.org/release/GRECLIPSE/e3.7">http://dist.springsource.org/release/GRECLIPSE/e3.7</a></code></code></td></tr></tbody></table><h2>Development Builds</h2><table class="confluenceTable"><tbody><tr><th class="confluenceTh">Eclipse level</th><th class="confluenceTh">Development update site</th></tr><tr><td class="confluenceTd">4.2 (Juno)</td><td class="confluenceTd"><code><a href="http://dist.springsource.org/snapshot/GRECLIPSE/e4.2">http://dist.springsource.org/snapshot/GRECLIPSE/e4.2</a></code></td></tr><tr><td class="confluenceTd">3.7 (Indigo)</td><td class="confluenceTd"><code><code><a href="http://dist.springsource.org/snapshot/GRECLIPSE/e3.7">http://dist.springsource.org/snapshot/GRECLIPSE/e3.7</a></code></code></td></tr></tbody></table><p>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.</p><h3>Where to find more information and ask questions</h3><table class="wysiwyg-macro" data-macro-name="info" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2luZm99&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>Please ask all questions on the <a href="http://xircles.codehaus.org/lists/eclipse-plugin-user@groovy.codehaus.org">Groovy-Eclipse mailing list</a>. Any bugs or feature enhancements should go on <a href="http://jira.codehaus.org/browse/GRECLIPSE">Groovy-Eclipse's jira</a>.</p></td></tr></table><p>The compiler plugin was originally described <a href="http://contraptionsforprogramming.blogspot.com/2010/09/where-are-all-my-stubs.html">here</a> and <a href="http://contraptionsforprogramming.blogspot.com/2010/10/more-on-groovy-eclipse-and-maven.html">here</a>, but these posts are no longer updated and this page will always contain the more recent information.</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced