Several types of Maven repositories

In the context of Maven, a "repository" refers to a storage location for artifacts such as JAR files, POM files, and other resources needed during the build and deployment processes. There are several types of Maven repositories, and their differences can be summarized as follows:


1. Local Repository

  • Description: A repository located on your local machine where Maven stores all downloaded dependencies.

  • Default Location :

    • ~/.m2/repository (on Linux/Mac)
    • C:\Users\<User>\.m2\repository (on Windows)
  • How It Works :

    • When you build a Maven project, it first looks for dependencies in the local repository.
    • If not found, it downloads from remote repositories and caches them locally.
  • Configuration : Can be customized in the settings.xml file.

    <localRepository>/path/to/local/repo</localRepository>


2. Remote Repository

  • Description: A central location on the internet or an organization's network that hosts Maven artifacts.

  • Examples :

    • Maven Central (https://repo.maven.apache.org/maven2/)
    • JCenter (deprecated)
    • Custom Nexus/Artifactory repositories.
  • Usage :

    • Maven queries remote repositories if the dependency is not found locally.
  • Configuration : Add remote repositories in the pom.xml or settings.xml.

    <repositories> <repository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories>


3. Central Repository

  • Description: The default remote repository used by Maven to download dependencies.
  • URL : https://repo.maven.apache.org/maven2/
  • Characteristics :
    • Publicly accessible.
    • Maintained by the Maven project.
  • No Additional Configuration Required :
    • Maven uses this repository by default unless explicitly overridden.

4. Private/Corporate Repository

  • Description: A repository set up by an organization to host internal or third-party artifacts not available in public repositories.

  • Tools :

    • Nexus Repository Manager
    • JFrog Artifactory
    • AWS CodeArtifact
  • Benefits :

    • Enhanced control over dependencies.
    • Secure and private storage for proprietary code.
  • Configuration :

    <repositories> <repository> <id>corporate-repo</id> <url>https://my.corporate.repo/repository/maven-releases/</url> </repository> </repositories>


5. Snapshot Repository

  • Description : Dedicated to hosting -SNAPSHOT artifacts, which represent development versions of a project.

  • Usage :

    • When a project is under development, frequent updates may occur.
    • SNAPSHOT versions are updated dynamically in the repository.
  • Configuration Example :

    <repositories> <repository> <id>snapshots</id> <url>https://my.corporate.repo/repository/maven-snapshots/</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>


6. Release Repository

  • Description: Hosts stable and released versions of artifacts (non-SNAPSHOT versions).

  • Usage :

    • Used for production-ready artifacts.
    • Once deployed to the release repository, the artifacts are immutable.
  • Configuration Example :

    <repositories> <repository> <id>releases</id> <url>https://my.corporate.repo/repository/maven-releases/</url> <releases> <enabled>true</enabled> </releases> </repository> </repositories>


Key Differences Between Maven Repositories:

Type Location Purpose Example URL
Local Repository Local filesystem Cache dependencies locally for faster builds. ~/.m2/repository
Remote Repository Internet or network server Fetch dependencies not found locally. https://repo.maven.apache.org/maven2/
Central Repository Internet Default repository for Maven. https://repo.maven.apache.org/maven2/
Private Repository Private network Store proprietary or internal artifacts. https://my.corporate.repo/...
Snapshot Repository Internet/Private network Host development artifacts (-SNAPSHOT). https://my.repo.com/maven-snapshots/
Release Repository Internet/Private network Host production-ready, immutable artifacts (non-SNAPSHOT). https://my.repo.com/maven-releases/
相关推荐
用户0304805912632 分钟前
Spring Boot 配置文件加载大揭秘:优先级覆盖与互补合并机制详解
java·后端
青莲8433 分钟前
Java内存回收机制(GC)完整详解
java·前端·面试
CRUD酱7 分钟前
微服务分模块后怎么跨模块访问资源
java·分布式·微服务·中间件·java-ee
gAlAxy...10 分钟前
5 种 SpringBoot 项目创建方式
java·spring boot·后端
lalala_lulu12 分钟前
什么是事务,事务有什么特性?
java·开发语言·数据库
沛沛老爹35 分钟前
深入理解Agent Skills——AI助手的“专业工具箱“实战入门
java·人工智能·交互·rag·企业开发·web转型ai
蓝程序1 小时前
Spring AI学习 程序接入大模型(HTTP接入)
java·spring
小途软件1 小时前
ssm607家政公司服务平台的设计与实现+vue
java·人工智能·pytorch·python·深度学习·语言模型
星火开发设计1 小时前
二叉树详解及C++实现
java·数据结构·c++·学习·二叉树·知识·期末考试
Ahtacca1 小时前
解决服务间通信难题:Spring Boot 中 HttpClient 的标准使用姿势
java·spring boot·后端