Gradle does not use the Maven Local Repository for a new dependency

(Manuel Jordan) #1


I have Maven with M2_HOME defined to:

  • /Users/manuelj/apache/maven/3.2.5

I have the settings.xml file, located on:

  • /Users/manuelj/apache/maven/3.2.5/conf/settings.xml

where I have the following declared:


Until here with Maven all works fine. Any new dependency goes there.

I have a project based with Gradle, among many things in my build.gradle, exists the following:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'application'

version = '1.0.0'
sourceCompatibility = '1.8'

repositories {

… more

Until here, all works fine too. Code compile, executes well.

My confusion is the following.

According with my understanding is that Gradle’s mavenLocal() should use the same path than <localRepository> defined on Maven’s settings.xml file.

Now confirming that in the Maven local repository exists some dependencies already downloaded.

When I execute for example gradle build, I did realize that

  1. If a dependency already exists from the Maven Local Repository, it is used from there.
  2. If a dependency does not exists from the Maven Local Repository Gradle download the new dependency to: /Users/manuelj/.gradle/caches/modules-2/files-2.1

I want that the new dependency go directly to the same Maven Local Repository.

Therefore, what extra configuration is need it?

Thanks in advanced

Gradle settings.xml file equivalent from Maven to define a global Local Repository

Any plans to have gradle support this feature of specifying custom place to download dependencies?

(Carlo Luib-Finetti) #3

I don’t think Gradle will use the local Maven repository as a writeable one. Gradle has it’s own local repository, aka Gradle cache, which is a quite different thing. You can specify the location in an environment variable, i.e. (on Windows) “set GRADLE_USER_HOME=D:\Java\gradle-prj\gradleCache”.

(Dimitar Dimitrov) #4

In Gradle “repository” and “cache” are two different concepts. In Maven they are one concept, with the local repo being auto-updated.

In Gradle a repository is a source for artifacts, with varying degrees of metadata (i.e. an Ivy repo can have very rich metadata, Maven - less so, file dump - even less). A cache keeps a copy of what was retrieved from the repository with some extra information - i.e. where it was retrieved from, and others. The rich cache allows Gradle to cope with some scenarios Maven cannot.

The cache is internal Gradle concept and is not supposed to be touched by humans. Its internal format is not public and parts of it change over time to accommodate new requirements. As such using Gradle cache as a repository is a bad idea.

If you just want to store the cache in a different location, then the easiest way is to use a custom $GRADLE_USER_HOME - it would also take care of the cached Gradle Wrapper distributions. Here is some step by step instructions and the manual.

(uklance) #5

I believe that the OP just wants to publish artifacts to maven local directory. See publishing to maven local

The “maven-publish” plugin makes this easy to do by automatically creating a PublishToMavenLocal task for each MavenPublication in the publishing.publications container