标题: Several types of Maven repositories [打印本页] 作者: 乌市泽哥 时间: 2024-12-27 04:28 标题: 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.