Interface Repository

All Known Subinterfaces:
LocalRepository, RemoteRepository
All Known Implementing Classes:
DefaultLocalRepository, DefaultRemoteRepository

@Experimental @Immutable public interface Repository

In Maven, repositories are locations where project artifacts (such as JAR files, POM files, and other resources) are stored and retrieved. There are two primary types of repositories: local repositories and remote repositories.

Repository Resolution Process

When resolving dependencies, Maven follows this order:

  1. Check Local Repository: Maven first checks if the artifact is available in the local repository.
  2. Check Remote Repositories: If the artifact is not found locally, Maven queries the configured remote repositories in the order they are listed.
  3. Download and Cache: If Maven finds the artifact in a remote repository, it downloads it and stores it in the local repository for future use.

By caching artifacts in the local repository, Maven minimizes the need to repeatedly download the same artifacts, thus optimizing the build process.

Repository Configuration

Repositories can be configured at various levels:

  1. POM: Repositories can be specified in the pom.xml file under the <repositories> and <pluginRepositories> sections.
  2. Settings: the settings.xml can be used to provide additional repositories in the three level of settings (user, project, installation).
By understanding and properly configuring repositories, developers can control where Maven looks for dependencies, manage access to proprietary artifacts, and optimize the build process to ensure consistency and reliability across projects.
Since:
4.0.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The reserved id for Maven Central
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the identifier of this repository.
    Gets the type of the repository, for example "default".
  • Field Details

  • Method Details

    • getId

      @Nonnull String getId()
      Gets the identifier of this repository.
      Returns:
      the (case-sensitive) identifier, never null
    • getType

      @Nonnull String getType()
      Gets the type of the repository, for example "default".
      Returns:
      the (case-sensitive) type of the repository, never null