# How to Fix Maven Dependency Not Found Error

Your Maven build fails with dependency resolution errors:

bash
[ERROR] Failed to execute goal on project myapp: Could not resolve dependencies for project com.myapp:myapp:jar:1.0.0:
[ERROR] Failed to collect dependencies at org.example:missing-lib:jar:1.2.3: Failed to read artifact descriptor for org.example:missing-lib:jar:1.2.3:
[ERROR]     Could not find artifact org.example:missing-lib:jar:1.2.3 in central (https://repo.maven.apache.org/maven2)

Or:

bash
[ERROR] The following artifacts could not be resolved: com.example:mylib:jar:2.0.0 (absent):
[ERROR]   Could not find artifact com.example:mylib:jar:2.0.0

Maven can't find a dependency you declared. This could be a typo, missing repository, wrong version, or network issue.

Diagnosis Steps

Step 1: Verify Dependency Exists

Search Maven Central:

```bash # Search on command line mvn dependency:get -Dartifact=org.example:missing-lib:1.2.3

# Or search Maven Central website # https://search.maven.org/search?q=g:org.example%20AND%20a:missing-lib ```

Step 2: Check Spelling and Format

Verify the dependency coordinates in pom.xml:

xml
<dependency>
    <groupId>org.example</groupId>      <!-- Check exact spelling -->
    <artifactId>missing-lib</artifactId> <!-- Check exact spelling -->
    <version>1.2.3</version>              <!-- Check if version exists -->
</dependency>

Step 3: Check Available Versions

```bash # List available versions mvn versions:display-dependency-updates -Dincludes=org.example:missing-lib

# Or use API curl -s "https://search.maven.org/solrsearch/select?q=g:org.example+AND+a:missing-lib&rows=20&core=gav&wt=json" | jq '.response.docs[] | .v' ```

Step 4: Check Repository Configuration

bash
# Effective POM shows all repositories
mvn help:effective-pom | grep -A 5 "<repositories>"

Step 5: Force Dependency Update

bash
# Force update from remote repositories
mvn clean install -U

Step 6: Check Local Cache

bash
# Check if cached locally (might be corrupted)
ls ~/.m2/repository/org/example/missing-lib/

Solutions

Solution 1: Fix Wrong Coordinates

Common coordinate mistakes:

```xml <!-- WRONG - groupId usually has dots --> <dependency> <groupId>example-org</groupId> <artifactId>missing-lib</artifactId> <version>1.2.3</version> </dependency>

<!-- CORRECT --> <dependency> <groupId>org.example</groupId> <artifactId>missing-lib</artifactId> <version>1.2.3</version> </dependency> ```

Solution 2: Add Missing Repository

If the library is not in Maven Central, add the appropriate repository:

```xml <repositories> <!-- JitPack for GitHub projects --> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository>

<!-- JBoss repository --> <repository> <id>jboss-public-repository</id> <url>https://repository.jboss.org/nexus/content/groups/public/</url> </repository>

<!-- Google Android repository --> <repository> <id>google</id> <url>https://maven.google.com</url> </repository>

<!-- Sonatype snapshots --> <repository> <id>sonatype-snapshots</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> ```

For GitHub projects using JitPack:

```xml <repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories>

<dependencies> <!-- Replace com.github.User with actual GitHub user/org --> <!-- Replace ProjectName with repo name --> <!-- Replace Tag with commit hash, branch, or release tag --> <dependency> <groupId>com.github.User</groupId> <artifactId>ProjectName</artifactId> <version>Tag</version> </dependency> </dependencies> ```

Solution 3: Use Correct Version

bash
# Find latest version
curl -s "https://search.maven.org/solrsearch/select?q=g:com.google.guava+AND+a:guava&rows=1&sort=version+desc&wt=json" | jq '.response.docs[0].latestVersion'

Update pom.xml:

xml
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>33.0.0-jre</version>  <!-- Use latest stable -->
</dependency>

Solution 4: Clear Corrupted Cache

```bash # Remove specific dependency from cache rm -rf ~/.m2/repository/org/example/missing-lib/

# Remove all cached dependencies (nuclear option) rm -rf ~/.m2/repository/

# Then rebuild mvn clean install -U ```

Solution 5: Handle Snapshots Properly

For snapshot versions:

```xml <dependency> <groupId>org.example</groupId> <artifactId>experimental-lib</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency>

<repositories> <repository> <id>sonatype-snapshots</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories> ```

Force snapshot update:

bash
mvn clean install -U -DallowSnapshots=true

Solution 6: Install Local JAR

If you have the JAR locally but it's not in any repository:

bash
# Install to local repository
mvn install:install-file \
   -Dfile=path/to/library.jar \
   -DgroupId=com.example \
   -DartifactId=my-library \
   -Dversion=1.0.0 \
   -Dpackaging=jar

Then use in pom.xml:

xml
<dependency>
    <groupId>com.example</groupId>
    <artifactId>my-library</artifactId>
    <version>1.0.0</version>
</dependency>

For a multi-module project or to share, deploy to a local file repository:

xml
<distributionManagement>
    <repository>
        <id>local-repo</id>
        <url>file://${project.basedir}/local-repo</url>
    </repository>
</distributionManagement>

Solution 7: Configure Proxy for Corporate Network

If behind a corporate proxy:

xml
<!-- In ~/.m2/settings.xml -->
<settings>
    <proxies>
        <proxy>
            <id>corporate-proxy</id>
            <active>true</active>
            <protocol>https</protocol>
            <host>proxy.company.com</host>
            <port>8080</port>
            <username>proxyuser</username>
            <password>proxypass</password>
            <nonProxyHosts>localhost|127.0.0.1|*.internal.com</nonProxyHosts>
        </proxy>
    </proxies>
</settings>

Solution 8: Fix Mirror Configuration

If mirrors are misconfigured:

xml
<!-- In ~/.m2/settings.xml -->
<settings>
    <mirrors>
        <mirror>
            <id>aliyun-maven</id>
            <mirrorOf>central</mirrorOf>
            <name>Aliyun Maven Mirror</name>
            <url>https://maven.aliyun.com/repository/public</url>
        </mirror>
    </mirrors>
</settings>

Solution 9: Use Dependency Management for Version Alignment

When multiple modules need same version:

```xml <dependencyManagement> <dependencies> <dependency> <groupId>org.example</groupId> <artifactId>example-lib</artifactId> <version>2.0.0</version> </dependency> </dependencies> </dependencyManagement>

<dependencies> <!-- Version inherited from dependencyManagement --> <dependency> <groupId>org.example</groupId> <artifactId>example-lib</artifactId> </dependency> </dependencies> ```

Solution 10: Exclude Conflicting Transitive Dependencies

```xml <dependency> <groupId>com.example</groupId> <artifactId>some-library</artifactId> <version>1.0.0</version> <exclusions> <exclusion> <groupId>org.conflicting</groupId> <artifactId>conflicting-lib</artifactId> </exclusion> </exclusions> </dependency>

<!-- Add the correct version explicitly --> <dependency> <groupId>org.conflicting</groupId> <artifactId>conflicting-lib</artifactId> <version>2.0.0</version> </dependency> ```

Verification

After fixes, verify the dependency resolves:

```bash # Show dependency tree mvn dependency:tree -Dincludes=org.example:missing-lib

# Check for dependency conflicts mvn dependency:analyze

# Show dependency resolution mvn dependency:resolve -DincludeScope=compile

# List all dependencies mvn dependency:list ```

Create a verification script:

```bash #!/bin/bash # check-dependency.sh

GROUP_ID=$1 ARTIFACT_ID=$2 VERSION=$3

echo "Checking: $GROUP_ID:$ARTIFACT_ID:$VERSION"

# Try to download mvn dependency:get \ -DgroupId=$GROUP_ID \ -DartifactId=$ARTIFACT_ID \ -Dversion=$VERSION \ -Dtransitive=false \ -q

if [ $? -eq 0 ]; then echo "✓ Dependency found and downloaded" else echo "✗ Dependency not found"

# Search for alternatives echo -e "\nSearching for available versions..." curl -s "https://search.maven.org/solrsearch/select?q=g:$GROUP_ID+AND+a:$ARTIFACT_ID&rows=10&core=gav&wt=json" | \ jq -r '.response.docs[] | "\(.v) (id: \(.id))"' fi ```

Common Dependency Sources

Library TypeRepository
Most Java librariesMaven Central
Spring librariesSpring Milestones/Snapshots
HibernateJBoss Repository
Android librariesGoogle Maven
GitHub projectsJitPack.io
Early releasesSonatype OSS Snapshots

Quick Reference

ErrorCauseSolution
Could not find artifactWrong coordinatesVerify groupId, artifactId, version
Could not transfer artifactNetwork/firewallCheck proxy, mirrors
Invalid artifactCorrupted cacheDelete from ~/.m2/repository
Missing snapshotNo snapshot repoAdd snapshots repository
Version not foundVersion doesn't existSearch for correct version
Access deniedPrivate repositoryAdd authentication

When a dependency can't be found, start by verifying coordinates against Maven Central, check repository configuration, and ensure the version exists.