Implementing Maven plugins has never been Groovier!
Groovy Maven plugins are very similar to Java Maven plugins. Actually a Groovy Maven plugin is compiled into Java byte-code, and once built, Maven can not tell the difference between a plugin which has been implemented in Java or Groovy.
For the most part, the existing guide for developing Maven plugins with Java will also apply to developing plugins with Groovy. This guide will cover the basics of how to create a plugin using Groovy as well as some finer points about how using Groovy can make plugin development faster and easier.
First off, please read over the documentation for Building Groovy Projects. A Groovy Maven plugin is a Groovy project, so most of the information there is relevant here as well.
Most mojos need to report back some failure status, which is normally done by throwing a
MojoExecutionException. Groovy Mojos can simply invoke the fail() method, which handles the details of throwing for you.
Failing with a simple string:
Failing with an exception detail:
Failing with an exception detail and a message:
To help get Groovy plugins started faster, you can use the
gmaven-archetype-mojo. This will create a new project with the basic POM configuration and an example Groovy-based Mojo class 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: