create eclipse groovy-java project with maven

Here is configuration I found that works when Java calls Groovy code and when Groovy calls Java code fitting good within groovy eclipse IDE plugin (nature).

There is no need for additional source folders for groovy. It just works!

Using:

mvn clean install eclipse:clean eclipse:eclipse
<dependencies>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.0.4</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerId>groovy-eclipse-compiler</compilerId>
                <verbose>true</verbose>
                <extensions>true</extensions>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-compiler</artifactId>
                    <version>2.7.0-01</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <additionalProjectnatures>
                    <projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
                </additionalProjectnatures>
                <sourceIncludes>
                    <sourceInclude>**/*.groovy</sourceInclude>
                </sourceIncludes>
            </configuration>
        </plugin>
    </plugins>
</build>

There is another best way to create maven groovy project. Please follow below steps:

  • Navigate to https://start.spring.io/ from your browser.
  • Select project as maven and language as groovy as shown below. selection image
  • Select other options as per your build requirement like packaging, java version and project name.
  • Now click on Generate radio button at the bottom and a maven groovy project will be downloaded.
  • Open Eclipse and import the downloaded maven project and it's ready to use for your groovy scripting with maven integration.

If you would like to create a Groovy project just by calling mvn eclipse:eclipse you have to configure your project. As follows a snippet how you configure your maven eclipse plugin so that your project becomes a Groovy project in Eclipse. That snippet must go into your projects pom.xml by the way.

...
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-eclipse-plugin</artifactId>
      <configuration>
        <additionalProjectnatures>
          <projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
        </additionalProjectnatures>
        <sourceIncludes>
          <sourceIncludes>**/*.groovy</sourceIncludes>
        </sourceIncludes>
      </configuration>
    </plugin>
  </plugins>
</build>
...

When you now call mvn eclipse:eclipse maven creates the .project and .classpath files. .project contains the new project nature what makes it a Groovy project and .classpath contains the */*.groovy* what makes Eclipse treating any file that ends on .groovy as a source file.

Please see also http://maven.apache.org/plugins/maven-eclipse-plugin/examples/provide-project-natures-and-build-commands.html


You should try the Groovy-Eclipse m2eclipse integration. It is available here:

http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/

With this installed, your maven projects will be automatically configured as groovy-eclipse projects when you import them into your workspace.