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.






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 repository, src/it/groovy directory.


Last modified on Jan 16, 2017

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.