Maven plugins can be written in Java or any of a number of scripting languages. Plugins consists of one or more Mojos, each one being the implementation for one of the plugin's goals.

NOTE: this documentation covers Mojo API introduced in Maven 2 and used by Maven 3. It does not cover the new Maven 4 API.

Although the requirements on Mojos are minimal by design, there are still a very few requirements that Mojo developers must keep in mind:

  1. a Mojo must have a method named execute which declares no parameters, and has a void return type. If this method throws an exception, that exception must either be a derivative of java.lang.RuntimeException, or a derivative of org.apache.maven.plugin.MojoExecutionException. It goes without saying that in the latter case, the execute method must declare that it throws this exception.
  2. Additionally, Mojos must declare a field for each goal parameter they specify, and these parameter fields will be populated before execute() is called.
  3. Finally, all Mojos must be accompanied by metadata in META-INF/maven/plugin.xml describing parameters, lifecycle bindings, etc. This descriptor will be covered in more detail below.

Mojo Code

Basically, these Mojo requirements are embodied by the org.apache.maven.plugin.Mojo interface, which the Mojo must implement.
Usually this is done by extending its abstract base class counterpart org.apache.maven.plugin.AbstractMojo.
The Mojo will have access to the standard Maven user-feedback mechanism, org.apache.maven.plugin.logging.Log, so the Mojo can communicate important events to the console or other log sink.

The Descriptor and Annotations

As mentioned before, each Plugin - or packaged set of Mojos - must provide a META-INF/maven/plugin.xml descriptor file inside the Plugin jar file.
Fortunately, Maven also provides a set of Java annotations (named Maven Plugin Tools Java5 Annotations) and tools (named Plugin Tools) to generate this descriptor, so developers don't have to worry about directly authoring or maintaining a separate XML metadata file.

Project Descriptor (POM) Requirements

The POM must declare a packaging element which describes this project as a Maven plugin project: <packaging>maven-plugin</packaging>


This section simply gives a listing of pointers for more information.

  • Maven Plugin API [ link ]
  • MojoDescriptor API [ link ]