Dependency Search Sequence in Maven
퇽회 Definition
The Dependency Search Sequence refers to the order in which Apache Maven looks for required libraries (dependencies) when building a project.
퇽훹 Search Order
When a dependency is needed, Maven follows this sequence:
1. Local Repository
- First, Maven checks the local system (
.m2/repository) - If found ᭒ used directly
- No internet required
2. Central Repository
- If not found locally, Maven checks the central repository (online)
- Downloads the dependency if available
3. Remote Repository
- If still not found, Maven checks configured remote repositories
- Typically used in organizations (e.g., Nexus, Artifactory)
퇽훹 Flow Representation
Local ᭒ Central ᭒ Remote
퇽훹 Step-by-Step Process
- Dependency is declared in
pom.xml - Maven searches in Local Repository
- If missing ᭒ searches Central Repository
- If still missing ᭒ searches Remote Repository
- Once found ᭒ downloads and stores in Local Repository
- Used for build process
퇽훹 Example
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
Ⅱ Maven automatically follows the search sequence to locate this library.
퇽훹 Importance
- Ensures fast builds (local caching)
- Enables automatic dependency resolution
- Reduces manual effort
- Supports offline development
- Improves efficiency in CI/CD pipelines
