You are previewing Maven: The Definitive Guide.

Maven: The Definitive Guide

Cover of Maven: The Definitive Guide by Sonatype Company Published by O'Reilly Media, Inc.

Plugin Descriptor

A Maven plugin contains a road map for Maven that tells Maven about the various Mojos and plugin configurations. This plugin descriptor is present in the plugin JAR file in META-INF/maven/plugin.xml. When Maven loads a plugin, it reads this XML file, and instantiates and configures plugin objects to make the Mojos contained in a plugin available to Maven.

When you are writing custom Maven plugins, you will almost never need to think about writing a plugin descriptor. In Chapter 10, the lifecycle goals bound to the maven-plugin packaging type show that the plugin:descriptor goal is bound to the generate-resources phase. This goal generates a plugin descriptor off the annotations present in a plugin’s source code. Later in this chapter, you will see how Mojos are annotated, and you will also see how the values in these annotations end up in the META-INF/maven/plugin.xml file.

Example 17-1 shows a plugin descriptor for the Maven Zip plugin. This plugin is a contrived plugin that simply zips up the output directory and produces an archive. Normally, you wouldn’t need to write a custom plugin to create an archive from Maven; you could simply use the Maven Assembly plugin that is capable of producing a distribution archive in multiple formats. Read through the plugin descriptor in this example to get an idea of the content it contains.

Example 17-1. Plugin descriptor

<plugin> <description></description> <groupId></groupId> <artifactId>maven-zip-plugin</artifactId> ...

The best content for your career. Discover unlimited learning on demand for around $1/day.