Skip to content

Repositories

Estimated time to read: 2 minutes

What is a repository?

Repositories are generally a http accessible location where files can be downloaded from.

Default Repository Location

The default location for these repositories are set within the super pom.xml which sits alongside the Maven installation.

The super pom.xml points Maven towards http://repo.maven.apache.org for its artefacts.

Overriding / Adding repositories

It is possible to add Corporate or Third-Party repositories to Maven. These repositories are often running Nexus or Artifactory at their backend.

Adding a repository to Maven is as simple as adding an element to the pom.xml file for the project.

<repositories>
 <repository>
  <id>spring-repo</id>
  <url>https://repo.spring.io/release/</url>
 </repository>
</repositories>

Local Repository

Maven looks within the ~/.m2 directory for its local repository. It stores artefacts within the following structure: ~/.m2/repository/<groupId>/<artifactId>

Dependency Repository

A dependency repository is a repository where dependencies are downloaded from. It can contain releases and / or snapshots, though it is not uncommon for these to be in separate repositories.

More elements can be parsed in the pom.xml file to set further options in Maven

<repositories>
 <repository>
  <id>spring-snapshot</id>
  <name>Spring Maven SNAPSHOT Repository</name>
  <url>https://repo.springsource.org/libs-snapshot</url>
  <snapshots>
   <enabled>true</enabled>
  </snapshots>
  <releases>
   <enabled>false</enabled>
  </releases>
 </repository>
</repositories>

Plugin Repositories

A plugin repository is identical to a dependency repository for the most part. They are separated from a dependency repository however primarily as a way of organising artefacts. More information can be found 205 - Plugins.

Release / SNAPSHOT Repositories

Releases and SNAPSHOT versions can be stored in a single repository, however, this is not good practise.

Releases tend to be deployed to a central repository so that artefacts can be accessed by all.

Snapshots, Milestones, Release Candidates and others tend to be stored on a corporate server so that they can be separated from Releases.