GMaven has kick-ass support for compiling Groovy projects with Maven!
Groovy projects are structured based on the Maven standard, notably adding the
groovy sub-directory to the
test source collections:
To help get Groovy projects started faster, you can use the
gmaven-archetype-basic. This will create a new project with the basic POM configuration and some example classes to get you started quickly:
The Maven Archetype Plugin will ask a few questions about your new project:
The above example would have created the following project structure:
GMaven provides support to compile Groovy sources, which includes joint Java/Groovy compilation via stub-generation.
To enable compilation features configure the
gmaven-plugin execute the stub-generation and compilation goals in your projects POM and define a dependency on the Groovy runtime your project requires (using the
default version in this example:
By default, all
*.groovy files under
src/main/groovy will be compiled into
target/classes and all
*.groovy files under
src/test/groovy will be compiled into
To use a more specific list of sources, specify one or more source filesets. When sources is specified the default location is not automatically included:
Many of the options available in the Groovy compiler configuration can also be set:
For the full reference of available flags please see the plugin documentation for the groovy:compile goal.
Stub-generation creates minimal Java sources for each Groovy class preserving the class structure and Javadocs, but omitting implementation detail. This allows the standard Maven Compiler Plugin to be used to compile Java sources which have a dependency upon Groovy sources with out any additional POM configuration or magical hacks.
Stub class files are used for resolving classes at compile-time, at runtime the compiled Groovy classes will be used instead.
Stub source files are used for generating API documentation via the standard Maven Javadoc Plugin, other plugins which operate on source files (ex. Maven JXR Plugin) will also utilize these generated source files for reports.
Test execution works just like any normal Maven project using the Maven Surefire Plugin. Using the
testCompile goal, the GMaven plugin will compile Groovy sources into Java class files, which the Surefire plugin will execute just like any other Java class.
Be sure to configure your project's to depend on the required Groovy runtime and the desired unit-testing library (using
junit3 in this example):
Non-Groovy projects can still make use of Groovy for testing... which can make for less verbose test classes