官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 河津市| 漳州市| 肥东县| 白水县| 茌平县| 青海省| 望谟县| 土默特左旗| 七台河市| 都江堰市| 清苑县| 漳浦县| 道孚县| 凉山| 如皋市| 英山县| 嘉峪关市| 葫芦岛市| 卢龙县| 平果县| 福海县| 开原市| 老河口市| 策勒县| 罗江县| 宜兰县| 哈密市| 合作市| 延长县| 大英县| 普格县| 南郑县| 盐源县| 额敏县| 永登县| 台北县| 南城县| 西林县| 余姚市| 玛沁县| 宁国市|