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:
<localRepository>/Users/manuelj/apache/maven/repository</localRepository>
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 { mavenLocal() mavenCentral() } … 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
/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?
Gradle's local repository folder is: $USER_HOME/. gradle/caches/modules-2/files-2.1.
repositories { mavenLocal() } Gradle uses the same logic as Maven to identify the location of your local Maven cache. If a local repository location is defined in a settings. xml , this location will be used.
Gradle can consume dependencies available in the local Maven repository. Declaring this repository is beneficial for teams that publish to the local Maven repository with one project and consume the artifacts by Gradle in another project. Gradle stores resolved dependencies in its own cache.
Maven and Gradle can be configured to consume dependencies from the same proxy. This setup is quite common in professional environments and my personal preference. Thanks by the reply, Remember I want that the new dependencies gotten through Gradle go to the Maven Local Repository.
Under the covers Gradle resolves dependencies from the respective URL of the public repository defined by the shorthand notation. All shorthand notations are available via the RepositoryHandler API.
When searching for a module in a repository, Gradle, by default, checks for supported metadata file formats in that repository. In a Maven repository, Gradle looks for a .pom file, in an ivy repository it looks for an ivy.xml file and in a flat directory repository it looks directly for .jar files as it does not expect any metadata.
Gradle is able to resolve artifacts stored in the local Maven repository (usually ~/.m2/repository
) via mavenLocal().
According to the documentation, mavenLocal()
is resolved like this:
Gradle uses the same logic as Maven to identify the location of your local Maven cache. If a local repository location is defined in a
settings.xml
, this location will be used. Thesettings.xml
inUSER_HOME/.m2
takes precedence over thesettings.xml
inM2_HOME/conf
. If nosettings.xml
is available, Gradle uses the default locationUSER_HOME/.m2/repository
.
To resolve artifacts from a non-standard local Maven repository, you can use the following configuration in your build.gradle
:
repositories { maven { url '/Users/manuelj/apache/maven/repository' } }
(From: How does Gradle resolve the directory of the local maven repository?)
Custom Maven repositories are documented here.
Gradle stores resolved dependencies in its own Dependency Cache. The dependency cache is so much more than just a simple Maven artifact repository:
jcenter()
might be different to the one resolved from mavenCentral()
.Artifacts produced by the build can be easily pushed to the local Maven repository via publishToMavenLocal
task contributed by the Maven Publish Plugin.
But what about resolved dependencies? For the aforementioned reasons, Gradle cannot store dependencies in the local Maven repository. There's currently no built-in functionality to even publish dependencies to the Maven's local repository from the build script. So what are your options:
Use
mavenLocal()
for example:
buildscript { ext { springBootVersion = '2.0.0.M1' } repositories { mavenCentral() mavenLocal() maven { url "https://repo.spring.io/snapshot" } maven { url "https://repo.spring.io/milestone" } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() mavenLocal() maven { url "https://repo.spring.io/snapshot" } maven { url "https://repo.spring.io/milestone" } } dependencies { compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-web') compile('com.oracle:ojdbc6:11.2.0.4') testCompile('org.springframework.boot:spring-boot-starter-test') }
I am using Gradle 3.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With