Gradle cannot find a dependency that is in ~/.m2 (mavenLocal)
Gradle reports that it could not find com.example:my-lib:1.0.0Short 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.
Fix it fast
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/2Match what you see, then jump to its fix
- 1
The error lists the repositories Gradle tried, and the local Maven one is not among themmavenLocal() is not declared where this dependency is resolvedFix - 2
The module is in a folder you know, but not under ~/.m2/repositoryGradle looks in a different folder than the one Maven wrote toFix - 3
The version folder exists but a .pom or .jar file is missingThe local module is incompleteFix - 4
Gradle downloads a different build of the same coordinates, or an older version, from a remote repositoryAnother repository answers firstFix
- 1
What does the error look like?
Gradle reports that it could not find com.example:my-lib:1.0.0The 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 runtimeClasspathConfirmed by docs.gradle.org
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/repository2Fix
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 install3Verify
List the installed module under the folder Gradle reads.
ls ~/.m2/repository/com/example/my-lib/1.0.0/Confirmed by docs.gradle.org
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 install3Verify
Both files now appear, and the dependency resolves.
ls ~/.m2/repository/com/example/my-lib/1.0.0/
./gradlew buildConfirmed by docs.gradle.org
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 runtimeClasspath2Fix
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 runtimeClasspathConfirmed by docs.gradle.org
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
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile 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 fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fixMobile 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