Skip to content

Gradle Dependency Not Found Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Gradle Dependency Not Found Fix. We cover key concepts, practical examples, and best practices.

Your Gradle build fails with Could not resolve dependency, Unable to find artifact, or Dependency not found — the dependency's Maven coordinates are incorrect, the repository is missing, or the version does not exist.

Step-by-Step Fix

1. Check the Maven coordinates

// Wrong: incorrect group ID, artifact ID, or version
dependencies {
    implementation 'com.squareup.okhttp3:okhttp:4.99.0'  // Version may not exist
    implementation 'okhttp:okhttp:4.12.0'  // Wrong group ID
}

// Right: verify coordinates on Maven Central
dependencies {
    implementation 'com.squareup.okhttp3:okhttp:4.12.0'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
}

Verify the dependency at search.maven.org or mvnrepository.com.

2. Add the correct repository

// Wrong: missing the repository that hosts the dependency
buildscript {
    repositories {
        google()
        mavenCentral()
    }
}

// Right: add the specific repository for the dependency
buildscript {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }        // For JitPack hosted libraries
        maven { url 'https://plugins.gradle.org/m2/' }  // For Gradle plugins
    }
}

// Example: using a JitPack dependency
dependencies {
    implementation 'com.github.User:Repo:Tag'
}

3. Use dynamic versions with care

// Wrong: using version ranges or + (unpredictable builds)
dependencies {
    implementation 'com.squareup.okhttp3:okhttp:4.+'      // May break at any time
    implementation 'com.squareup.okhttp3:okhttp:latest.release'  // Not recommended
}

// Right: use fixed versions for reproducible builds
dependencies {
    implementation 'com.squareup.okhttp3:okhttp:4.12.0'
}

// Only use dynamic versions for internal libraries
dependencies {
    implementation 'com.mycompany:internal-lib:1.+'
}

4. Fix transitive dependency conflicts

// Wrong: two dependencies pulling different versions of the same library
dependencies {
    implementation 'com.squareup.okhttp3:okhttp:4.12.0'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'  // Pulls okhttp 3.x
}

// Right: force a consistent version
configurations.all {
    resolutionStrategy {
        // Force a specific version of okhttp
        force 'com.squareup.okhttp3:okhttp:4.12.0'

        // Or prefer the latest version
        failOnVersionConflict()
        // Or use checkResults to see what resolves
    }
}

// Or exclude transitive dependencies
dependencies {
    implementation('com.squareup.retrofit2:retrofit:2.9.0') {
        exclude group: 'com.squareup.okhttp3', module: 'okhttp'
    }
    implementation 'com.squareup.okhttp3:okhttp:4.12.0'
}

5. Check the dependency tree

# View the full dependency tree
./gradlew dependencies --configuration implementation

# Filter for a specific dependency
./gradlew dependencies --configuration runtimeClasspath | grep okhttp

Expected output:

runtimeClasspath - Runtime classpath of source set 'main'.
+--- com.squareup.okhttp3:okhttp:4.12.0
|    +--- com.squareup.okio:okio:3.6.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.22
\--- com.squareup.retrofit2:retrofit:2.9.0
     \--- com.squareup.okhttp3:okhttp:3.14.9 -> 4.12.0 (version forced)

6. Refresh dependencies after changes

# Clear dependency cache
./gradlew clean

# Re-download all dependencies
./gradlew build --refresh-dependencies

# Use the --refresh-dependencies flag to bypass cache
./gradlew dependencies --refresh-dependencies

7. Use BOM for aligned versions

// Use a Bill of Materials (BOM) to manage consistent versions
dependencies {
    // Import a BOM
    implementation platform('com.squareup.okhttp3:okhttp-bom:4.12.0')

    // These versions are all aligned by the BOM
    implementation 'com.squareup.okhttp3:okhttp'
    implementation 'com.squareup.okhttp3:logging-interceptor'
    implementation 'com.squareup.okhttp3:okhttp-sse'
}

Prevention

  • Always use fixed dependency versions for reproducible builds.
  • Verify dependency coordinates on Maven Central before adding them.
  • Use ./gradlew dependencies to inspect the full dependency tree.
  • Use BOM files for libraries that provide them (AWS SDK, OkHttp, etc.).
  • Run ./gradlew build --refresh-dependencies after changing dependencies.

Common Mistakes with dependency error

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world GRADLE code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

What does "Could not find dependency" mean?

Gradle searched all configured repositories and could not find the artifact with the specified group ID, artifact ID, and version. Check the coordinates and the repository URLs. |||How do I find the correct Maven coordinates for a library? Search for the library on mvnrepository.com or search.maven.org. Copy the implementation declaration directly from the page. |||What is the difference between implementation and api dependencies? implementation makes the dependency available only to the current module. api exposes it to consumers. Use implementation by default and only use api when the dependency is part of the module's public API.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro