Compiling Groovy with GMaven plugin
Configuring the GMaven Plugin for Groovy Support in Maven 2 and 3
If you are using Clover-for-Maven 2 and 3 on Groovy code, you would typically need to define a plugin
element for the GMaven Plugin in your pom.xml
file.
As shown in the example definition below, the GMaven Plugin definition requires the Groovy dependency (groovy-all
). However, within this dependency, you must define a version of Groovy that Clover supports inside a version
sub-element. If you omit this version
element, the GMaven Plugin will default to using Groovy version 1.6.0, which is not compatible with Clover.
<properties>
<groovy.version>1.8.8</groovy.version>
<gmaven.version>1.5</gmaven.version>
</properties>
...
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>${gmaven.version}</version>
<configuration>
<providerSelection>1.8</providerSelection>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-1.8</artifactId>
<version>${gmaven.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Tips
Cross-compilation
If you use cross-compilation with Groovy code, please refer to the Cross Compilation using Groovy on the Best Practices for Maven page.
Stub generation
Use the clover:setup goal for Clover instrumentation in case you have generateStubs or generateTestStubs goal declared in GMaven plugin configuration.
In case you use clover:instrument a build will fail with an error message like:
org.apache.maven.BuildFailureException: Compilation failure
... error: duplicate class: com.acme.MyClass
A reason is that GMaven will generate stubs twice and will add /generated-sources/groovy-stubs source root for both the default build life cycle (/target) and the Clover's forked build life cycle (/target/clover) resulting in duplicated source files passed to the Maven compiler.
Setting the providerSelection
Remember to configure a providerSelection parameter. Otherwise build might fail with the following error: "org.apache.maven.lifecycle.LifecycleExecutionException: Unexpected node: Node[7:1,64,ANNOTATIONS]" (see stackoverflow).
Code example
See https://bitbucket.org/atlassian/maven-clover2-plugin repository, src/it/groovy directory.