Running latest Groovy from Maven
Say you have a groovy-project that you build with maven. You use the org.codehaus.gmaven:gmaven-plugin to compile your groovy code and run groovy tests without a problem. Then you add some features or tests that need groovy 1.7. You add the proper dependency and version to the <dependencies> section of your pom, run your test… and watch it blow up because the gmaven-plugin defaults to using groovy 1.6. So you dig around on the web and find references for how to use the <providerSelection> tag of the gmaven-plugin to get your code compiled with 1.7 and to use 1.7 when running tests. Things seem good. Until…
You add a feature that requires some version of groovy greater than 1.7.4 (the version included with the latest gmaven-plugin, 1.3). In my case, I used the @Delegate annotation with some inheritance in a test configuration and hit a bug that was fixed in groovy 1.7.6. No matter what version I used in my dependencies section, my tests were executed under groovy 1.7.4. I finally came up with the configuration below which let me run with a different groovy. Note that it made no difference what I included in the dependencies section. The gmaven-plugin configuration appears to be completely independent of that.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<configuration>
<providerSelection>1.7</providerSelection>
<!-- This is only used if you want to run a groovy script from the command line using maven -->
<source>${groovy.script}</source>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<!-- This block is required in order to make the gmaven plugins use a groovy other than 1.7.4.
This is independent of the groovy entry in the dependencies section. This does not affect the class path.
What is interesting is that there must be both the gmaven.runtime entry with the explicit excludes
and the additional dependency on whatever version we do want to use. If you exclude the former,
it will throw an exception. -->
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-1.7</artifactId>
<version>1.3</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.6</version>
</dependency>
</dependencies>
</plugin>