Maven coordinates

Maven coordinates identify uniquely a project, a dependency, or a plugin defined in POM. Each entity is uniquely identified by the combination of a group identifier, an artifact identifier, and the version (and, of course, with the packaging and the classifier). The group identifier is a way of grouping different Maven artifacts. For example, a set of artifacts produced by a company can be grouped under the same group identifier. The artifact identifier is the way you identify an artifact, which could be JAR, WAR, or any other type of an artifact uniquely within a given group. The version element lets you keep the same artifact in different versions in the same repository.

Note

A valid Maven POM file must have groupId, artifactId, and version. The groupId and the version elements can also be inherited from the parent POM file.

All these three coordinates of a given Maven artifact are used to define its path in the Maven repository. If we take the following example, the corresponding JAR file is installed in the local repository with the USER_HOME/.m2/repository/com/packt/sample-one/1.0.0/ path:

<groupId>com.packt</groupId>
<artifactId>sample-one</artifactId>
<version>1.0.0</version>

If you have gone through the elements of the super POM file carefully, you might have noticed that it does not have any of the previously mentioned elements. No groupId, artifactId, or version. Does this mean that the super POM file is not a valid POM? The super POM file is like an abstract class in Java. It does not work by itself; it must be inherited by a child POM file. Another way to look at the super POM file is that it's the Maven's way of sharing default configurations.

Once again, if you look at the <pluginManagement> section of the super POM file, as shown in the following code snippet, you will notice that a given plugin artifact is identified only by its artifactId and version elements. This contradicts what we mentioned before; a given artifact is uniquely identified by the combination of groupId, artifactId, and version. How is this possible?

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.3</version>
</plugin>

There is an exception for plugins. You need not specify groupId for a plugin in the POM file; it's optional. By default, Maven uses org.apache.maven.plugins or org.codehaus.mojo as groupId. Have a look at the following section in MAVEN_HOME/conf/settings.xml. If you want to add additional group IDs for plugin lookup, you have to uncomment the section below and add them there:

  <!-- pluginGroups
   | This is a list of additional group identifiers that 
   | will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". 
   | Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" 
   | if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin
     | lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

Note

We will be discussing Maven plugins in detail in Chapter 5, Maven Plugins.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.233.43