Four Easy Steps to Providing Help for your Maven Plugin

· maven

This is easy, it is supported out of the box.

Step 1 - make sure each mojo has the JavaDoc, this will be used to generate your help files. E.g.:

	/**
	 * Create and provision each of the boxes defined in src/main/vbox.
	 *
	 * @goal provision
	 * @phase pre-integration-test
	 */
	public class ProvisionMojo extends AbstractVBoxesMojo {
	
		/**
		 * Which targets in the Provision.xml to execute, or all if "*".
		 *
		 * @parameter expression="${vbox.provision.targets}", default="*"
		 */
		protected String targets = "*";

Step 2 - add the "helpmojo" goal to your plugin.

	            <plugin>
	                <groupId>org.apache.maven.plugins</groupId>
	                <artifactId>maven-plugin-plugin</artifactId>
	                <version>3.2</version>
	                <executions>
	                    <execution>
	                        <id>generated-helpmojo</id>
	                        <goals>
	                            <goal>helpmojo</goal>
	                        </goals>
	                    </execution>
	                </executions>
	            </plugin>

Step 3 - execute "mvn install".

Step 4 - test by executing "mvn vbox:help" (substitute your own plugin's name), you'll see something like this.

...

A Maven plugin for creating, starting, and stopping VirtualBoxes.

This plugin has 8 goals:

...

vbox:help
  Display help information on vbox-maven-plugin.
  Call mvn vbox:help -Ddetail=true -Dgoal=<goal-name> to display parameter
  details.

...

vbox:provision
  Create and provision each of the boxes defined.
...

An example of the usage can be found on GitHub. And I've written tips on writing Maven plugins before.