It's the 1st time to use gradle in our project and we're using the local maven repository. Now I have a question: Is it possible to make gradle download dependency merging into local maven repository automatically? Is there any configuration or plugin to resolve? Thanks a lot!
2 Answers
Short answer is: no way!
Gradle has its own cache, although it can read the maven local repo like this:
repositories {
mavenLocal()
mavenCentral()
}
If some dependency not found in maven local repo, Gradle will download it from maven central and cache it in ~/.gradle/caches/...
see http://forums.gradle.org/gradle/topics/cache_dependencies_into_local_maven_repository_from_gradle

- 121
- 2
- 9
Although Gradle has its own cache, the files are stored in a structure similar to that of Maven local repository. To update Maven local with dependencies from Gradle cache, here are the task and configuration for that (tested with Gradle 7.5):
repositories {
mavenLocal()
}
dependencies {
// Place your dependencies here
}
build {
finalizedBy 'cacheToMavenLocal'
}
task cacheToMavenLocal(type: Copy) {
from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1')
into repositories.mavenLocal().url
eachFile {
List<String> parts = it.path.split('/')
it.path = [parts[0].replace('.','/'), parts[1], parts[2], parts[4]].join('/')
}
includeEmptyDirs false
}
The task was copied and adapted from @Adrodoc55's answer on Gradle forum.
As an addendum:
Using the maven-publish plugin's publishToMavenLocal
task, Gradle will publish the project's build artifacts (e.g. resulting .jar file) to Maven local.
gradle publishToMavenLocal

- 2,052
- 1
- 13
- 29