Tuesday, June 5, 2007

Getting Groovy with Maven

The problem:

You would like to integrate Groovy scripts into your Maven application.

The solution:

Maven has a plug-in for groovy! You should put your scripts into "src/main/groovy", and test scripts into "src/test/groovy". To make groovy compile add this plug-in definition to your pom:


<build>
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
...
</build>


and then this dependency:


<dependency>
<groupId>groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.0-jsr-04</version>
</dependency>


Thats all there is to it! Now go script up a storm.