Repositories and coordinates
Maven 2 repositories store a collection of artifacts used by Maven during dependency resolution for a project. Local repositories are accessed on the local disk, and remote repositories are accessed through the network.
An artifact is usually bundled as a JAR file containing the binary library or executable. This is known as an artifact's type. In practice, however, an artifact can also be a WAR, EAR, or other code-bundling type.
Maven 2 takes advantage of an operating system's directory structure for quick indexing of the collection of artifacts stored within a repository. This repository index system relies on the ability to identify any artifact uniquely via its coordinate.
A Maven coordinate is a tuple of values that uniquely identifies any artifact. A coordinate comprises three pieces of information:
- The group ID: The entity or organization responsible for producing the artifact. For example,
com.ibm.devworkscan be a group ID.
- The artifact ID: The name of the actual artifact. For example, a project with a main class called
OpsImpas its artifact ID.
- The version: A version number of the artifact. The supported format is in the form of
mmmis the major version number,
nnnis the minor version number, and
bbbis the bugfix level. Optionally, either
dd(build number) can also be added to the version number.
Maven coordinates are used throughout Maven configuration and POM files. For example, to specify a project dependency on a module entitled
OpsImp at the 1.0-SNAPSHOT level, a pom.xml file includes the segment shown in Listing 1:
Listing 1. Maven coordinate for an example OpsImp module
<dependencies> <dependency> <groupId>com.ibm.devworks</groupId> <artifactId>OpsImp</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>
SNAPSHOT qualifier tells Maven 2 that the project or module is under development and that it should fetch the latest copy of the artifact available.
To specify that the project depends on JUnit for unit testing, JUnit 3.8.1's coordinates can be added as a dependency in the project's pom.xml, as shown in Listing 2:
Listing 2. Maven coordinate for a JUnit dependency
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> </dependency> </dependencies>
Because Maven repositories are ordinary directory trees, you can readily take a look at how artifacts are stored on disk. Figure 3 is a portion of the local repository, showing the location of the JUnit 3.8.1 artifact:
Figure 3. Inside a Maven 2 repository
In Figure 3, you can see that Maven maintains an artifact's POM file, together with checksum hashes for both the artifact and its POM in the repository. These files help ensure artifact integrity when artifacts are transferred between repositories. This artifact has been downloaded from the central repository and placed into the local repository by Maven's dependency management engine.
In Figure 4, the artifact with coordinates
com.ibm.devworks/OpsImp/1.0-SNAPSHOT is shown in the local repository. The artifact is in the directory together with the POM file. In this case, the artifact is installed locally.
Figure 4. OpsImp artifact in a local repository