Groovy in Java EE with Maven

Version 1.1 by Ken McWilliams on 2012/04/17 06:07

It is quite easy to add Groovy support. Once the support is in place you can use Groovy as you would use regular Java.  As a matter of fact to test out Groovy we will create a Struts2 action with it!

Following assumes we have set up a basic struts2 application using Maven:

1) In Netbeans, expand the "Project Files" and open pom.xml.

2a) Locate the maven compiler plugin, which in my poms typically looks like the following:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>

2b) Edit this pom.xml such that the above looks like the following:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <compilerId>groovy-eclipse-compiler</compilerId>
                    <verbose>true</verbose>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-compiler</artifactId>
                        <version>2.6.0-01</version>
                    </dependency>
                </dependencies>
            </plugin>