Setting descriptions for mojos and parameters in maven plugin

Viewed 181

I am writing a maven plugin and I would like to add some documentation for the available goals and parameters.

When I run mvn help:describe -Dplugin=myplugin -Ddetail it prints out available goals and parameters. However it lists (no description) everywhere. From searching the internet I could not figure out where such a description is to be set.

For reference, my plugin is written in scala and looks roughly like this.

import org.apache.maven.plugins.annotations.{ Component, Parameter }


class MyMojo extends AbstractMojo {

 @Parameter(defaultValue = "false", readonly = false)
 private var skipFormatting: Boolean = _

}

So my question would be: where can set a description, such that it will show up with mvn help:describe -Dplugin=myplugin?

2 Answers

I strongly recommend to use the following:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>3.6.0</version>
    <executions>
      <execution>
        <id>default-descriptor</id>
        <phase>process-classes</phase>
      </execution>
      <execution>
        <id>generate-helpmojo</id>
        <goals>
          <goal>helpmojo</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

which will generate the help part during the build process. And yes you have to add some javadoc like this:

@Mojo(name = "failure", defaultPhase = LifecyclePhase.NONE,
    requiresDependencyResolution = ResolutionScope.NONE, threadSafe = true)
public class FailureMojo extends AbstractMojo {

I don't understand why you haven't have any annotations on your Mojo?

The documentation like this: https://maven.apache.org/plugins/maven-install-plugin/plugin-info.html will be generated from the javadoc on parameters etc. https://github.com/apache/maven-install-plugin/blob/master/src/main/java/org/apache/maven/plugins/install/InstallMojo.java#L69

Based on examples when running the help:describe on familiar plugins like the maven-jar-plugin, tt appears it's based on the Javadoc of the Mojo class.

Related