Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create eclipse groovy-java project with maven

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

like image 904
Dónal Avatar asked Feb 11 '11 16:02

Dónal


People also ask

Can you use Maven with Groovy?

The execution of the Groovy script can be bound to any Maven phase; furthermore, inside the script, the objects session and project can be used to interact with the Maven build.

How do I run a project as Maven project in Eclipse?

Building and Running the Maven Project in Eclipse To run the maven project, select it and go to “Run As > Java Application”. In the next window, select the main class to execute. In this case, select the App class and click on the Ok button. You will see the “Hello World” output in the Console window.

Can we use Eclipse for Groovy?

The Apache Groovy programming language allows for easy interoperability between the Java and Collibra libraries. To add support for Groovy syntax highlight and auto-completion in Eclipse: In the menu bar, click Help → Install New Software….

Can we create Maven project in Eclipse?

Maven dependencies can be updated with the IDE, and Maven builds can be launched within Eclipse.


1 Answers

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>
like image 169
David Avatar answered Oct 24 '22 08:10

David