3.5.3. Maven Coordinates

The Archetype plugin created a project with a file named pom.xml. This is the Project Object Model (POM), a declarative description of a project. When Maven executes a goal, each goal has access to the information defined in a project’s POM. When the jar:jar goal needs to create a JAR file, it looks to the POM to find out what the JAR file’s name is. When the compiler:compile goal compiles Java source code into bytecode, it looks to the POM to see if there are any parameters for the compile goal. Goals execute in the context of a POM. Goals are actions we wish to take upon a project, and a project is defined by a POM. The POM names the project, provides a set of unique identifiers (coordinates) for a project, and defines the relationships between this project and others through dependencies, parents, and prerequisites. A POM can also customize plugin behavior and supply information about the community and developers involved in a project.

Maven coordinates define a set of identifiers which can be used to uniquely identify a project, a dependency, or a plugin in a Maven POM. Take a look at the following POM.

A Maven Project's Coordinates

Figure 3.4. A Maven Project's Coordinates


We've highlighted the Maven coordinates for this project: the groupId, artifactId, version and packaging. These combined identifiers make up a project's coordinates.[3]Just like in any other coordinate system, a set of Maven coordinates is an address for a specific point in "space". Maven pinpoints a project via its coordinates when one project relates to another, either as a dependency, a plugin, or a parent project reference. Maven coordinates are often written using a colon as a delimiter in the following format: groupId:artifactId:packaging:version. In the above pom.xml file for our current project, its coordinates are represented as mavenbook:my-app:jar:1.0-SNAPSHOT.

groupId

The group, company, team, organization, project, or other group. The convention for group identifiers is that they begin with the reverse domain name of the organization that creates the project. Projects from Sonatype would have a groupId that begins with com.sonatype, and projects in the Apache Software Foundation would have a groupId that starts with org.apache.

artifactId

A unique identifier under groupId that represents a single project.

version

A specific release of a project. Projects that have been released have a fixed version identifier that refers to a specific version of the project. Projects undergoing active development can use a special identifier that marks a version as a SNAPSHOT.

The packaging format of a project is also an important component in the Maven coordinates, but it isn't a part of a project's unique identifier. A project's groupId:artifactId:version make that project unique; you can't have a project with the same three groupId, artifactId, and version identifiers.

packaging

The type of project, defaulting to jar, describing the packaged output produced by a project. A project with packaging jar produces a JAR archive; a project with packaging war produces a web application.

These four elements become the key to locating and using one particular project in the vast space of other “Mavenized” projects . Maven repositories (public, private, and local) are organized according to these identifiers. When this project is installed into the local Maven repository, it immediately becomes locally available to any other project that wishes to use it. All you must do is add it as a dependency of another project using the unique Maven coordinates for a specific artifact.

Maven Space is a coordinate system of projects

Figure 3.5. Maven Space is a coordinate system of projects




[3] There is a fifth, seldom-used coordinate named classifier which we will introduce later in the book. You can feel free to ignore classifiers for now.