Using Plugin Tools Java5 Annotations

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

NOTE With annotations, it's not any more mandatory to have your Mojos super classes in the same project. Super classes can now come from reactor projects or external dependencies. As javadoc doclet are still useful 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 (sources classifier) to provide documentation (the tooling will skip error if this artifact sources is missing).

Pom configuration

    <!-- dependencies to annotations -->
      <!-- annotations are not needed for plugin execution so you can remove this dependency
           for execution with using provided scope -->
    <!-- generated help mojo has a dependency to plexus-utils -->
          <!-- see -->
          <!-- if you want to generate help goal -->


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 or Maven context components. See javadoc for more information.

Plugin Tools Java 5 Annotations (see full example) are named after Plugin Tools Javadoc Tags (see full example), with following little differences:

Plugin Tools Javadoc TagsPlugin Tools Java 5 Annotation
@goal "goal-name"@Mojo( name = "goal-name" )
@phase "<phase-name>"@Mojo( defaultPhase = "<phase-name>" )