Maven 2 and Groovy
I am currently trying to get unit tests written in groovy running for a maven project. First i thought this would be easy going but it is definitely not. First i tried the groovy-maven-plugin version 1.0-alpha-1-SNAPSHOT from the 27th of February.
As i want to compile my groovy unit test to java byte code I just inserted following XML snippet to my parent pom.xml:
-
<plugin>
-
<groupId>org.codehaus.mojo</groupId>
-
<artifactId>groovy-maven-plugin</artifactId>
-
<version>1.0-alpha-1-SNAPSHOT</version>
-
<executions>
-
<execution>
-
<phase>test-compile</phase>
-
<goals>
-
<goal>compile</goal>
-
</goals>
-
</execution>
-
<configuration>
-
<sourceDirectories>
-
${project.testSourceRoots}
-
</sourceDirectories>
-
</configuration>
-
</executions>
-
</plugin>
This approach did not work. If i tried to run mvn test the plugin did not get executed and if i tried mvn groovy:compile maven said that it could not find the correct version for plugin org.apache.maven.plugins:groovy-maven-plugin. Huuh? Why is maven not considering the configured group id? After playing around for a while with this problem and without finding any solution I decided to try another approach.
After a short internet research i found the following guide about compiling groovy with maven 2.
-
<plugin>
-
<artifactId>maven-antrun-plugin</artifactId>
-
<executions>
-
<execution>
-
<id>test-compile</id>
-
<phase>test-compile</phase>
-
<configuration>
-
<tasks>
-
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
-
<classpath refid="maven.compile.classpath"/>
-
</taskdef>
-
<mkdir dir="${project.build.testOutputDirectory}"/>
-
<groovyc destdir="${project.build.testOutputDirectory}"
-
srcdir="${basedir}/src/test/java/" listfiles="true">
-
<classpath refid="maven.test.classpath"/>
-
</groovyc>
-
</tasks>
-
</configuration>
-
<goals>
-
<goal>run</goal>
-
</goals>
-
</execution>
-
</executions>
-
</plugin>
This approach simply runs an ant task which executes the groovy compiler on all groovy files. For a simple project setup this approach works without problems but i run into some as I already have a maven-antrun-plugin in my parent pom.xml in the profile section. But profiles are not inherited to childs. This leads to some strange inheritance problems which i do not fully understand at the moment. Why they appear in the way the are appearing. As soon I've found a solution or at least found out the reason for the problems I run into I'll tell you. So stay tuned ![]()
1 comment February 28th, 2007