You will recall that in the section on using the Maven JaCoCo plugin, to generate code coverage we had to explicitly specify the projectId
and artifactId
values of the plugin to it from the command line. However, for most other plugins, we specified the plugin name without additional information.
We will see why we had to do this and how to avoid it.
settings
file (specifically the settings.xml
file in your home directory).<pluginGroups> <pluginGroup>org.jacoco</pluginGroup> </pluginGroups>
mvn clean jacoco:prepare-agent test jacoco:report
[INFO] [INFO] --- jacoco-maven-plugin:0.7.2.201409121644:report (default-cli) @ project-with-tests --- [INFO] Analyzed bundle 'Project with Tests' with 1 classes
There are two types of Maven plugins, which are as follows:
org.apache.maven.plugins
and org.codehaus.mojo
.All official plugins have the same groupId
, namely org.apache.maven.plugins
. They also have a convention for artifactId
: maven-${prefix}-plugin
, where prefix
stands for the plugin prefix, the short name to refer to the plugin.
The prefix used to reference the plugin can be customized as well. The prefix can be specified directly through the goalPrefix
configuration parameter on the Maven-plugin-plugin
of the plugin's pom
file.
So, when we run mvn clean
, Maven looks for the maven-clean-plugin
in the org.apache.maven.plugins
group.
What about third-party plugins? pluginGroups
lets Maven know the groupId
where it should search for additional plugins. So in the earlier case, Maven searched for plugins in the org.jacoco
group.
Third-party plugins should be named differently from official plugins. The conventional way to define the artifactId
for third-party plugins is ${prefix}-maven-plugin
. When specified in this way, Maven automatically identifies the shortcut name for the plugin. In the earlier case, as the artifactId
is jacoco-maven-plugin
, the shortcut is jacoco
.
Maven will always search specified pluginGroups
before it searches the following default groups:
org.apache.maven.plugins
org.codehaus.mojo
Maven takes the first match for the shortcut that it finds. For instance, if there is a clean
shortcut in a user-specified plugin in pluginGroups
, it will take precedence over a Maven Clean plugin.
13.59.227.82