Maven Terms
These are some basic terminologies used in Maven. We will be using these throughout the article.
Plugin
Maven is, in essence, a plugin execution framework. What it does is execute different plugins. The actual tasks, such as compiling, installing dependencies, etc., are done by plugins. Each plugin has goals defined in it. Each goal is a single task that the plugin performs. For example, the install plugin of maven provides the goals install and install-file.
MOJO
MOJO stands for Maven plain Old Java Object. It is a class that must extend the AbstractMojo class. A single Mojo class defines a single goal in the project/plugin. We specify metadata about the goal in this class. This includes the goal's name, description, if it's thread-safe, etc. We also implement the execute method, which actually executes the goal.
Descriptors
For each plugin, Maven generates descriptors. These are XML files that store the metadata of the plugin. These are called Plugin Descriptors. Maven generates them automatically, so developers don't have to manage a separate XML dataset.
Artifact
Artifact is a general software term - that means anything produced during the process of developing software. It can be an executable file, documentation, or anything else. In Maven, Artifacts usually refer to an executable file, such as a JAR or WAR file. They are produced as the result of a Maven build.
They are identified by groupId, artifactId, and version. Maven needs to be able to identify artifacts in case one artifact is needed in another project as a dependency.
The Various Maven Plugin Tools
There are multiple plugin tools that Maven uses. They all have different functions and purposes. We will look at all the plugin tools discussed in the structure above.
maven-plugin-plugin
The Maven Plugin Plugin creates Plugin Descriptors for any Mojos in the source code. They are included in the final output of the project - the executable JAR/WAR/EAR, etc, file. It also creates reports for the Mojos, metadata about artifacts, and help functions for the plugin.
Goals
-
plugin:descriptor -> this goal generates the descriptor for a plugin.
-
plugin:addPluginArtifactMetadata -> This goal adds metadata of artifacts used in a plugin to this project's artifact. This helps later when resolving dependencies and deploying the project.
-
plugin:helpmojo -> This goal generates a help mojo. The help mojo describes all the mojos in a plugin.
- plugin:help -> This displays help information on the maven-plugin-plugin.
maven-plugin-report-plugin
This plugin tool creates reports for the Mojos in the source code. The reports have information about the Mojos and the current state of the project. Reports are useful to display on the project's website.
Goals
- plugin-report:report -> This goal generates the plugin documentation. It generates one overview report, and one report each for each Mojo.
maven-plugin-tools-generator
This plugin tool uses the plugin descriptor information to generate content about the plugin. It generates XML Descriptor, HTML (to display on the website), documentation , and help goals.
It takes in-memory information about the plugin descriptors, and produces descriptors, documentation,etc.
maven-plugin-tool-api
This is the API that Maven provides to extract descriptors from Maven plugins. It's main component is the MojoScanner, which scans the source code and uses MojoDescriptorExtractors to extract plugin descriptors from the code.
MojoDescriptorExtractor is an abstract class, which means it is only a specification, not an implementation. Mojo plugins can be written in different ways, so each way needs its own extractor. We will see examples of these in this article.
maven-plugin-tools-java
This is an implementation of the maven-plugin-tool-api. It is used for Mojos that are annotated with Mojo Javadoc tags. In this method to create Mojos, we add the Mojo Javadoc annotations above our class in the form of comments, to specify the metadata about the Mojo. For example,
@goal <goal name> is used to specify the name of the goal.
@requiresOnline <false|true> is used to specify if the goal requires an Internet connection.
@phase specifies which phase the goal is a part of, such as compiling, packaging, testing, etc.
The plugin tool implements the MojoDescriptorExtractor class from the Maven Plugin Tool API. Its implementation is called the JavaJavasocMojoDescriptorExtractor. It extracts Mojo descriptors from the source code's Javadoc comments.
maven-plugin-tools-javadoc
The Javadoc tool is a tool that extracts documentation from comments. It can be used in any Java project, even without Maven. The comments should be in the Javadoc format. Doclets are programs in the Javadoc tool that generate HTML documentation from the source code comments.
By default, the default doclet is used. But, if we want to customize the HTML output, we can write our own doclet. The maven-plugin-tools-javadoc is a tool that provides doclets that can convert Mojo Javadoc annotations into HTML documentation.
maven-plugin-tools-annotations
This is an implementation of the maven-plugin-tool-api. It is used for Mojos that are annotated with Java Annotations for Mojos. In this, the annotations have slightly changed to a more modern format. This feature was only introduced in Java 5. It's format is as follows:
@Mojo(name = "<goal-name>",requiresOnline=<false|true>
//..Other specifications
)
@Execute (goal="<goal-name>", phase = LifecyclePhase.<phase>)

You can also try this code with Online Java Compiler
Run Code
In this method, we separate the Mojo metadata from Execution Metadata. Additionally, compile-time checks are also performed. IDEs also offer autocompletion in this method, as this is not commenting. We are also able to specify values by Enum, such as LifecyclePhase. Earlier, we had to type Strings because it was comments.
The plugin tool implements the MojoDescriptorExtractor class from the Maven Plugin Tool API. Its implementation is called the JavaAnnotationsMojoDescriptorExtractor. It extracts Mojo descriptors from the source code's Javadoc comments.
maven-plugin-annotations
This tool provides the Java annotations that are used in Mojos described above.
It provides different annotations for Mojo, Execute, Parameter,etc.
maven-scripts
This is a project that allows us to write Maven plugins, Mojos and goals using scripting languages instead of Java. The 2 major scripts used are Beanshell and Ant. Let's look at both of them. However, scripting support for Mojos has recently been deprecated. Maven will remove it from maven 4.0 onwards.
maven-plugin-tools-beanshell
This is an extractor for Mojos written in Beanshell. It implements the MojoDescriptorExtractor class. Its implementation is called BeanshellMojoDescriptorExtractor. The tags used for beanshell Mojos are the same as the tags used in the Mojos that use Javadoc tags.
maven-script-beanshell
This is itself a maven plugin. If we want to write Mojos using Beanshell, we need to use this plugin to provide that functionality. As this is a plugin itself, it implements the maven-plugin-api. maven-plugin-api is an API that plugins must implement, so Maven can understand them and execute them as plugins.
maven-plugin-tools-ant
This is an extractor for Mojos written in Ant. It implements the MojoDescriptorExtractor class. Its implementation is called AntMojoDescriptorExtractor. If we are using Ant, we need to write the XML descriptor for the Mojo ourselves. Along with that, we need to write an XML Ant Script that should be executed to build the plugin.
maven-script-ant
This is itself a maven plugin. If we want to write Mojos using Ant, we need to use this plugin to provide that functionality. As this is a plugin itself, it implements the maven-plugin-api.
maven-plugin-tools-model
This tool provides a model that is used to extract descriptor information from plugins that are made using scripts. This tool generates Java documentation, plugin descriptor metadata, as well as an XML Schema Definition (XSD) file. XSD files are used to specify the format and definition of how a particular XML file should look. Here, the XSD file is used to specify how the descriptor XML should look.
Frequently Asked Questions
What's the difference between plugins and Mojos?
Mojos are goals that perform a single task. Each plugin can contain many different goals. Hence, every plugin can contain multiple Mojos.
What's the difference between XML and XSD files?
XML files are used to store data. XSD files are used to specify how the XML files should store data. We can specify a structure of elements, elements that are necessary, and what their type should be.
How can I write my own doclet?
The Javadoc tool lets you write your own doclet, which allows you to customize the output. We can write our own doclet by implementing the doclet API, which is available online freely.
Conclusion
This blog has explored the plugin tools used in Maven. We have seen how they are structured, and we have explored various plugin tools. We have seen their goals, and for what they are used.
We hope you leave this article with a broader knowledge of Java, Maven, and software project management. We recommend that you explore our different articles on these topics as well, such as:
What do you mean by Maven
Introduction to Maven Command
Ant vs Maven
You can practice questions on various problems on Coding Ninjas Studio, attempt mock tests. You can also go through interview experiences, interview bundle, go along guided paths for preparations, and a lot more!
Keep coding, keep reading Ninjas.