How to Fix Maven Dependency Not Found Error
In this tutorial, you'll learn about How to Fix Maven Dependency Not Found Error. We cover key concepts, practical examples, and best practices.
The Problem
You run mvn clean install and get:
[ERROR] Failed to execute goal on project myapp: Could not resolve dependencies for project
[ERROR] The following artifacts could not be resolved:
[ERROR] com.example:library:jar:2.0.0 was not found
Maven cannot find the specified dependency in any configured repository.
Quick Fix
Step 1: Verify the dependency coordinates
Check pom.xml for typos:
<dependency>
<groupId>com.example</groupId>
<artifactId>library</artifactId>
<version>2.0.0</version>
</dependency>
The group ID, artifact ID, and version must match exactly what is published. Check the official repository (Maven Central, company Nexus) for the correct coordinates.
Step 2: Check available repositories
<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
<repository>
<id>company-nexus</id>
<url>https://nexus.company.com/repository/maven-public/</url>
</repository>
</repositories>
If the dependency is in a private repository, ensure the repository URL and credentials are correct.
Step 3: Clear the local repository cache
rm -rf ~/.m2/repository/com/example/library/
mvn clean install
A corrupted or incomplete download in the local Maven repository can cause this error. Deleting the specific directory forces a fresh download.
Step 4: Force update snapshots
mvn clean install -U
The -U flag forces Maven to check for updated snapshots and releases regardless of the update policy in settings.
Step 5: Check settings.xml for credentials
If the repository requires authentication, add credentials to ~/.m2/settings.xml:
<servers>
<server>
<id>company-nexus</id>
<username>deployuser</username>
<password>deploypass</password>
</server>
</servers>
The server id must match the repository id in pom.xml.
Step 6: Search Maven Central manually
curl -s "https://search.maven.org/solrsearch/select?q=g:com.example+AND+a:library&rows=1&wt=json" | jq .
This verifies the artifact exists on Maven Central. If it does not, the artifact may be in a different repository or may not be published.
Step 7: Check proxy configuration
Add to ~/.m2/settings.xml:
<proxies>
<proxy>
<id>company-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.company.com</host>
<port>8080</port>
</proxy>
</proxies>
Network restrictions behind a corporate proxy require explicit proxy configuration.
Step 8: Run with debug output
mvn clean install -X | grep -A5 "repository"
The -X debug flag shows exactly which repositories Maven is searching and why it fails to resolve each artifact.
Alternative Solutions
Install the dependency manually:
mvn install:install-file -Dfile=library.jar -DgroupId=com.example -DartifactId=library -Dversion=2.0.0 -Dpackaging=jar
Common Errors
POM.xml not picking up settings.xml: Ensure id in the repository matches id in the server element. They must be identical for Maven to use the credentials.
Snapshot vs release confusion: If the dependency is a SNAPSHOT and Maven cannot find it, the snapshot repository may not be configured. Add <snapshots><enabled>true</enabled></snapshots> to the repository.
Network proxy blocking Maven: If Maven cannot reach any repository, check ~/.m2/settings.xml for proxy configuration or set MAVEN_OPTS="-DproxyHost=... -DproxyPort=...".
Dependency has transitive conflicts: Two dependencies pulling in different versions of the same library can cause mysterious errors. Run mvn dependency:tree to visualize the conflict and use <exclusions> to resolve it.
Prevention
- Pin specific versions in pom.xml instead of using
-SNAPSHOTfor production builds. - Use a repository manager (Nexus, Artifactory) as a single source of truth.
- Run
mvn dependency:treeto visualize the full dependency graph. - Validate pom.xml with
mvn validatebefore attempting a build.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro