Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle cannot find a dependency that is in ~/.m2 (mavenLocal)

ErrorGradle reports that it could not find com.example:my-lib:1.0.0

Short answer

Gradle only reads the local Maven cache when mavenLocal() is declared in the repositories that actually apply to that dependency. It finds the cache the way Maven does, the first matching repository wins, and half-installed modules fail. Check declaration, path, files on disk, then order.

  • Applies to Gradle 8.x, Gradle 9.x, Maven 3.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Confirm the module really sits in the local Maven repository and look at what is inside. Replace the group path and name with your own.

    ls -R ~/.m2/repository/com/example/my-lib/
  2. 2Match what you see, then jump to its fix

    1. 1The error lists the repositories Gradle tried, and the local Maven one is not among themmavenLocal() is not declared where this dependency is resolvedFix
    2. 2The module is in a folder you know, but not under ~/.m2/repositoryGradle looks in a different folder than the one Maven wrote toFix
    3. 3The version folder exists but a .pom or .jar file is missingThe local module is incompleteFix
    4. 4Gradle downloads a different build of the same coordinates, or an older version, from a remote repositoryAnother repository answers firstFix

What does the error look like?

  • Gradle reports that it could not find com.example:my-lib:1.0.0
  • The artifact exists under ~/.m2/repository but the Gradle build does not see it

Cause 1 of 4

mavenLocal() is not declared where this dependency is resolved

1Check

Gradle consumes a local Maven repository only when you declare it. Look for it in the repositories block that serves the failing configuration. With a settings-level repositories block in fail mode, a repository in a project file is itself a build error.

grep -rn "mavenLocal" settings.gradle* build.gradle* app/build.gradle*
grep -n "repositoriesMode\|dependencyResolutionManagement" settings.gradle*

2Fix

Declare mavenLocal() in the block that applies, which is the dependencyResolutionManagement block when the project uses one. Add it after your remote repositories, and limit it to the groups you publish locally.

dependencyResolutionManagement {
    repositories {
        mavenCentral()
        mavenLocal {
            content { includeGroup("com.example") }
        }
    }
}

3Verify

Resolve the dependency again.

./gradlew dependencies --configuration runtimeClasspath

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 4

Gradle looks in a different folder than the one Maven wrote to

1Check

Gradle finds the local Maven cache the way Maven does: a settings.xml in ~/.m2 takes precedence over M2_HOME/conf, and with no settings file the default is ~/.m2/repository.

ls ~/.m2/settings.xml "$M2_HOME/conf/settings.xml"
ls -d ~/.m2/repository

2Fix

Install the module with Maven as the same user that runs the Gradle build, so both use the same home directory and the same settings.xml lookup.

cd path/to/my-lib
mvn install

3Verify

List the installed module under the folder Gradle reads.

ls ~/.m2/repository/com/example/my-lib/1.0.0/

Confirmed by docs.gradle.org

Did this fix it?

Cause 3 of 4

The local module is incomplete

1Check

The Gradle manual describes the Maven local repository as a cache rather than a true repository, and notes it may hold incomplete modules, for example without sources or Javadoc. Gradle also does not trust local repositories because the origin of an artifact cannot be verified.

ls -l ~/.m2/repository/com/example/my-lib/1.0.0/

2Fix

Install the module again from its own project so that both the pom and the jar are written.

cd path/to/my-lib
mvn clean install

3Verify

Both files now appear, and the dependency resolves.

ls ~/.m2/repository/com/example/my-lib/1.0.0/
./gradlew build

Confirmed by docs.gradle.org

Did this fix it?

Cause 4 of 4

Another repository answers first

1Check

When a library is available in more than one declared repository, Gradle picks the first one. A remote repository listed before mavenLocal() wins.

./gradlew dependencyInsight --dependency my-lib --configuration runtimeClasspath

2Fix

Reorder so mavenLocal() comes first for the group you build locally, and keep the content filter so it serves only that group.

repositories {
    mavenLocal {
        content { includeGroup("com.example") }
    }
    mavenCentral()
}

3Verify

dependencyInsight reports why the dependency was selected and the path that brings it in.

./gradlew dependencyInsight --dependency my-lib --configuration runtimeClasspath

Confirmed by docs.gradle.org

Did this fix it?

How do I stop it coming back?

  • Publish shared libraries to a real internal repository instead of relying on ~/.m2 on one laptop.
  • If you must use mavenLocal(), filter it to your own groups so it cannot shadow public libraries.
  • Declare repositories in one place and keep the order deliberate.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Mobile apps

adb tcpip 5555 fails because no device is found

adb: more than one device/emulator

adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.