create eclipse groovy-java project with maven

10,081

Solution 1

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.

Solution 2

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>

Solution 3

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

Solution 4

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.
Share:
10,081

Related videos on Youtube

Dónal
Author by

Dónal

I earn a living by editing text files. I can be contacted at: [email protected] You can find out about all the different kinds of text files I've edited at: My StackOverflow Careers profile

Updated on May 20, 2022

Comments

  • Dónal
    Dónal almost 2 years

    I have a Java-Groovy Eclipse project that I build with Maven. I have added the Maven Groovy plugin to the pom.xml such that I can build/test the Java and Groovy sources on the command-line using Maven.

    I would like to have some way to automatically generate the Eclipse .project and .classpath files from my pom.xml. If I run mvn eclipse:eclipse it seems to assume that it's a Java project, so there's no way to (for example) run the tests in src/main/groovy from within Eclipse.

    I'm using the STS Eclipse distribution, which includes support for Groovy/Grails. All I'm missing is a way to automatically create the appropriate .classpath and .project files.

    Thanks!

    P.S. I know IntelliJ is better, but I don't have a license

  • Dónal
    Dónal about 13 years
    Thanks, this seems to work very well, is there an update site for full releases (as opposed to the snapshot update site)?
  • Andrew Eisenberg
    Andrew Eisenberg about 13 years
    No, we haven't moved this to a production update site yet. I don't expect that this functionality will change much over time.
  • AabinGunz
    AabinGunz over 10 years
    Thanks, it helped me too.