Using Java5 annotations

Since version 3.0, you can use Java5 annotations to generate the plugin descriptor file.

NOTE With annotations, it's not anymore mandatory to have your Mojos super classes in the same project. Super classe can now come from reactor projects or external dependencies. As javadoc doclet are still reading (for @since, @deprecated and comments), the sources are still scanned. So if you use an external dependency, you must still provide an artifact with sources (classifier sources) to provide documentation (the tooling will skip error if this artifact sources is missing).

Pom configuration

<project>
  ...
  <dependencies>
    <!-- dependencies to annotations -->
    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.0</version>
      <scope>compile</scope>
    </dependency>
    <!-- generated help mojo has a dependency to plexus-utils -->
    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-utils</artifactId>
      <version>3.0.1</version>
    </dependency>
  </dependencies>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
        </configuration>
        <executions>
          <execution>
            <id>mojo-descriptor</id>
            <goals>
              <goal>descriptor</goal>
            </goals>
          </execution>
          <!-- if you want to generate help goal -->
          <execution>
            <id>help-goal</id>
            <goals>
              <goal>helpmojo</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  ...
  </build>
  ...
</project>

Annotations

Information for plugin descriptor generation is specified using 4 annotations:

  • 2 class-level annotations:
    • @Mojo: This annotation will mark your class as a Mojo. See javadoc for more information.
    • @Execute: Used if your Mojo need to fork a lifecycle. See javadoc for more information.
  • 2 field-level annotations:
    • @Parameter: Used to configure your Mojo parameters. See javadoc for more information.
    • @Component: Used to configure injection of Plexus components. See javadoc for more information.