Friday, April 15, 2011

Using maven to build java+groovy projects

I have just started new project where I plan to use Java and Groovy at the same time. Groovy will be used primarily for implementing configuration DSL, and Java will implement core functionality. So I need some way to join Java and Groovy sources in one project.
I'm using maven for building, so it was natural to start searching plugin for maven. Well, after some minutes I have found Gmaven
First of all modify your pom.xml by adding Gmaven plugin

<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>

In order to make it compiling and running we need also groovy libraries

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.10</version>
</dependency>

The last thing to do is to create folders for groovy sources. Just make /src/main/groovy for sources and /test/main/groovy for tests