Repository (in Maven)
퇽회 Definition
A repository is a storage location where project artifacts (JAR files, libraries, plugins) are stored and retrieved.
In Apache Maven, repositories are used to download dependencies and store built packages.
퇽훹 Types of Maven Repositories
1. Local Repository
- Stored on your local system (e.g.,
.m2folder) - Caches downloaded dependencies
- Used for faster builds
퇽획 Example Path:C:\Users\Username\.m2\repository
2. Central Repository
- Default remote repository provided by Maven
- Contains thousands of open-source libraries
- Automatically accessed when dependencies are added
3. Remote Repository
- Hosted on a server (company or third-party)
- Used to share internal project libraries
- Examples: Nexus, Artifactory
퇽훹 How Maven Uses Repositories
When you add a dependency in pom.xml:
- Maven checks Local Repository
- If not found ᭒ checks Central Repository
- If still not found ᭒ checks Remote Repositories
- Downloads and stores it locally
퇽훹 Example (Dependency in pom.xml)
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.0</version>
</dependency>
Ⅱ Maven automatically downloads this from a repository.
퇽훹 Benefits of Using Repositories
- Easy dependency management
- Saves development time
- Ensures version consistency
- Supports team collaboration
- Enables reuse of components
퇽훹 Repository Managers
Tools used to manage repositories:
- Nexus Repository
- JFrog Artifactory
퇽훹 Importance
Repositories are essential because they:
- Act as a central library storage
- Enable automated builds
- Support CI/CD pipelines
Conclusion
Repositories in Maven simplify the process of managing, storing, and retrieving dependencies, making software development faster and more efficient.
