There is no Groovy code in the main
project,
but what we do here is to define the version, and where necessary
configuration, of dependencies used by the application's submodules. We
have classpath dependencies and build dependencies, so both are
defined.
There are three things to specify:
which version of the Groovy runtime to use
which version of GMaven to use. GMaven is the Groovy maven plugin that we use to compile Groovy, hosted at codehaus.org. By default GMaven specifies a version of the Groovy runtime to compile against, but this can be overridden
which version of Groovy Objects to use. Groovy Objects is not itself written in Groovy, but it does have a dependency on Groovy runtime. We want this to be in sync.
To start with, we specify the versions of these different
components, by adding the following to the
pom.xml
:
<properties> <groovy.version>1.7.2</groovy.version> <gmaven.version>1.2</gmaven.version> <gmaven.runtime>1.7</gmaven.runtime> <groovyobjects.version>0.1-SNAPSHOT</groovyobjects.version> </properties>
The gmaven.runtime
must be compatible with the
groovy.version
. Typically, if the
groovy.version
is x.y.z
, then the
gmaven.runtime
will be simply x.y
.
The documentation on GMaven
providers for further details; running mvn
groovy:providers
is a good place to start.
Note: Groovy Objects also has a dependency on the Groovy runtime, albeit in a very minor way. This dependency is marked optional in order to allow your application to specify its own Groovy runtime version which if needed can be different from that needed by Groovy Objects.
Next, we define how we to compile Groovy code, using the GMaven
plugin. We specify the plugin, the version, and its configuration; this
goes in
<build>/<pluginManagement>
:
<build> <pluginManagement> <plugins> ... <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>${gmaven.version}</version> <executions> <execution> <goals> <goal>compile</goal> <goal>testCompile</goal> </goals> </execution> </executions> <configuration> <providerSelection>${gmaven.runtime}</providerSelection> </configuration> </plugin> </plugins> </pluginManagement> </build>
Finally, we define the dependencies to Groovy
Objects and to Groovy. This goes in
<dependencyManagement>/<dependencies>
:
<dependencyManagement> <dependencies> ... <!-- Groovy Objects --> <dependency> <groupId>org.starobjects.groovy</groupId> <artifactId>gapplib</artifactId> <version>${groovyobjects.version}</version> </dependency> <dependency> <groupId>org.starobjects.groovy</groupId> <artifactId>gmetamodel</artifactId> <version>${groovyobjects.version}</version> </dependency> <!-- Groovy --> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>${groovy.version}</version> </dependency> </dependencies> </dependencyManagement>