Introduction to Maven Plugin Development
Maven consists of a core engine which provides basic project-processing capabilities and build-process management, and a host of plugins with their goals which are used to execute the actual build tasks.
What is a Plugin?
“Maven” is really just a core framework for a collection of Maven Plugins providing goals for execution. In other words, plugin goals are where much of the real action is performed, plugin goals are used to: create jar files, create war files, compile code, unit test code, create project documentation, and on and on. Almost any action that you can think of performing on a project is implemented as a goal provided by a Maven plugin.
Plugins are the central feature of Maven that allow for the reuse of common build logic across multiple projects. They do this by executing a goal, that is an “action” (i.e. creating a WAR file or compiling unit tests) in the context of a project's description - the Project Object Model (POM). Plugin behavior can be customized through a set of unique parameters which are exposed by a description of each plugin goal (implemented by a Mojo Java class).
One of the simplest plugins in Maven is the Maven Clean Plugin. The Maven Clean plugin (maven-clean-plugin) is responsible for removing the target/ directory of a Maven project, done by its unique clean goal. When you run “mvn clean:clean”, Maven executes the “clean” goal as defined in the Clean plugin, and the target/ directory is removed. The Clean plugin defines a parameter which can be used to customize plugin behavior: this parameter is called outputDirectory and it defaults to ${project.build.directory}.
What is a Mojo (And Why the H— is it Named ‘Mojo’)?
A Mojo is really just the Java implementation of a goal in Maven, and plug-ins consist of any number of goals / Mojos. Goals are defined as annotated Java classes = Mojos, and in the past as Beanshell script. A Mojo specifies metadata about a goal: a goal name, which phase of the lifecycle it fits into, and the parameters it is expecting.
MOJO is a play on POJO (Plain-old-Java-object), substituting “Maven” for “Plain”. Mojo is also an interesting word (see definition). From Wikipedia, a “mojo” is defined as: “…a small bag worn by a person under the clothes (also known as a mojo hand). Such bags were thought to have supernatural powers, such as protecting from evil, bringing good luck, etc.”
What is the Build Lifecycle? (Overview)
The build lifecycle is a series of common stages through which all project builds naturally progress. Plugin goals are bound to specific stages in the lifecycle.
See reference documentation for built-in lifecycles and default plugin goals bindings for built-in packagings.
The simplest lifecycle is the clean lifecycle, that provides a main clean stage with additional pre- and post- ones, and one single clean:clean plugin goal binding to the clean phase.
What is a Packaging?
The packaging defines what build steps your project executes during the default phase for a typical output expectation. Default packaging - jar - produces and tests a jar file. It is used by Maven projects by configuring <packaging>[packaging]</packaging> in your pom.xml.
Packaging is defined by associating (or binding) plugin goals to lifecycle phases: see for example default bindings for built-in packagings.
When you create a new plugin that produces a new type of output, you may want to create a new packaging that will define how to build and test such new output content.

