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/
相关推荐
香蕉大香蕉(06敬畏市场)19 分钟前
高频八股 · JVM(8)
java·jvm·面试·八股·大厂实习
养军博客27 分钟前
spirngSecurity 鉴权教程02
java·springsecurity
CoderYanger36 分钟前
Java EE 进阶:5. Spring IoC&DI(第二弹):Spring IoC
java·开发语言·spring boot·spring·面试·职场和发展·java-ee
悟天特斯1 小时前
安防一体化:从“各管各的“到“全局联动“
java·大数据·网络·人工智能·物联网
70后写java的老码农2 小时前
Spring Boot 3.x + ShardingSphere 5.x + MyBatis-Plus 3.x:订单分库分表实战(含两个踩坑记录)
java
霸道流氓气质2 小时前
AI 翻译插件:翻译记忆级联复用、术语混合检索与结构化质量门禁的 Vue3 + Spring AI 生产级实战
java·人工智能·spring
斯维赤2 小时前
OCR到底是接入第三方API 还是自己封装?
java·ocr
码智社2 小时前
Redis 哨兵模式详解:从原理到生产实践
java·redis
救救孩子把2 小时前
结构化输出为何“格式正确、答案错误”?JSON Schema 的能力边界
android·java·json·agent·agent服务
silvamux_2 小时前
微头条爆款体平台适配实测:把交付要求变成可计算的指标
java·线性代数·算法·决策树·矩阵