# Cache Dependencies into Local Maven Repository from Gradle

**URL:** <https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525>\
**Category:** Old Forum Archive\
**Created:** [November 8, 2011, 3:27pm UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525 "2011-11-08T15:27:00Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirinath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sirinath/32/76_2.png) [@sirinath](https://discuss.gradle.org/u/sirinath)\
**Post date:** [November 8, 2011, 3:27pm UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/1 "2011-11-08T15:27:00Z")

</div>

How to download and cache artifacts into local Maven Repository from Gradle

---

<div class="post-metadata">

**Author:** ![juha\_ranta](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@juha\_ranta](https://discuss.gradle.org/u/juha_ranta)\
**Post date:** [November 8, 2011, 3:52pm UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/2 "2011-11-08T15:52:00Z")

</div>

I’m not sure if this answers your answer. First of all, I’m new to Gradle.

First of all, Gradle has its own cache where it stores the downloaded artifacts. It resides in $HOME/.gradle, at least in Unix environments.

However, you can read the local Maven repository by putting this in your build.gradle:

```gradle
repositories {
     mavenLocal()
...
}

```

You can publish artifacts into the local Maven repository by putting into your build.gradle:

```gradle
apply plugin: 'maven'

```

Then you can write “gradle install” and it will install your artifact into your local Maven repository.

However, if you download artifacts from a remote Maven repo, Gradle will put the artifacts into its own cache, not in the local Maven repository.

---

<div class="post-metadata">

**Author:** ![sirinath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sirinath/32/76_2.png) [@sirinath](https://discuss.gradle.org/u/sirinath)\
**Post date:** [November 9, 2011, 3:14am UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/3 "2011-11-09T03:14:00Z")

</div>

I want the dependencies to be stored in the local Mavan Repo than the Gradle local repo

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [November 9, 2011, 8:20am UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/4 "2011-11-09T08:20:00Z")

</div>

Gradle will always store downloaded artifacts in its own cache. You can additionally use artifacts stored in the local Maven repository by declaring a ‘mavenLocal()’ repository. You can install into the local Maven repository by applying the ‘maven’ plugin and running the ‘install’ task.

---

<div class="post-metadata">

**Author:** ![sirinath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sirinath/32/76_2.png) [@sirinath](https://discuss.gradle.org/u/sirinath)\
**Post date:** [November 9, 2011, 9:27am UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/5 "2011-11-09T09:27:00Z")

</div>

Are the cached Jars moved to the local maven repo when installed or just the build artifacts?

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [November 9, 2011, 9:50am UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/6 "2011-11-09T09:50:00Z")

</div>

Only the build artifacts (i.e. what your gradle project built)

---

<div class="post-metadata">

**Author:** ![carlo\_lf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/carlo_lf/32/1881_2.png) [@carlo\_lf](https://discuss.gradle.org/u/carlo_lf)\
**Post date:** [February 21, 2012, 5:52pm UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/7 "2012-02-21T17:52:00Z")

</div>

indeed, this is something I am missing. Are there any plans to support the download to the local maven repository?

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [February 21, 2012, 5:59pm UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/8 "2012-02-21T17:59:00Z")

</div>

That’s not something that’s planned at this point, and not likely to be anytime soon.

---

<div class="post-metadata">

**Author:** ![slimsymphony](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/slimsymphony/32/1236_2.png) [@slimsymphony](https://discuss.gradle.org/u/slimsymphony)\
**Post date:** [May 30, 2012, 3:34am UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/9 "2012-05-30T03:34:00Z")

</div>

I think this is indeed important! I have to take so long to redownload the artifacts which I have downloaded.

---

<div class="post-metadata">

**Author:** ![carlo\_lf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/carlo_lf/32/1881_2.png) [@carlo\_lf](https://discuss.gradle.org/u/carlo_lf)\
**Post date:** [May 30, 2012, 8:04am UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/10 "2012-05-30T08:04:00Z")

</div>

It would be important if you have not only Gradle projects but also Maven projects which you cannot change or migrate. Then it would be an annoyance to have those duplicate jars.

On the other hand, if you a working in a team environment in the same network, a common repository like Artifactory can be configured as the primary repository for Gradle, and when Gradle asks Artifactory for some Jar which is not already it there it will be downloaded by Artifactory.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 30, 2012, 11:33am UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/11 "2012-05-30T11:33:00Z")

</div>

> I have to take so long to redownload the artifacts which I have downloaded.

Gradle already checks the local Maven repository for artifacts. If it finds an artifact with matching coordinates and checksum, it will _not_ download it again. (For best results, make sure to use a recent Gradle version.)

---

<div class="post-metadata">

**Author:** ![slimsymphony](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/slimsymphony/32/1236_2.png) [@slimsymphony](https://discuss.gradle.org/u/slimsymphony)\
**Post date:** [May 31, 2012, 1:53am UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/12 "2012-05-31T01:53:00Z")

</div>

That’s great, but I still think gradle doesn’t need to recreate a repo structure. Anyway it already use maven’s dependency management functionality.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [June 3, 2012, 6:07pm UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/13 "2012-06-03T18:07:00Z")

</div>

It’s very necessary to have our own repository for a few reasons. Moreover, to say that Gradle uses Maven’s dependency management functionality is incorrect.

---

<div class="post-metadata">

**Author:** ![carlo\_lf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/carlo_lf/32/1881_2.png) [@carlo\_lf](https://discuss.gradle.org/u/carlo_lf)\
**Post date:** [June 3, 2012, 8:00pm UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/14 "2012-06-03T20:00:00Z")

</div>

Luke: so please explain why it’s incorrect saying " Gradle uses Maven’s dependency management functionality". We all know, Gradle also supports Ivy and supports Maven repositories - by using them as a resource to resolve dependents. So, maybe we should be more concise: Gradle has it’s own dependency management strategy, but it can make usage of Maven and / or Ivy repositories. Anyway: the discussion on this pages, for me, is the question why Gradle cannot WRITE downloaded dependent artifacts back to a local Maven repository, given that a project defines a local Maven repository as the first source to look up for dependent artifacts. Think of this: if a developer has a local repository, he might be using it primary for his ‘old’ Maven based projects, and then he might also have some ‘new’ Gradle based project(s). So, why not have all those artifacts use a common code store? (In the “old days” days I always hated that each Java project had it’s own library directory.)

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [June 3, 2012, 9:56pm UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/15 "2012-06-03T21:56:00Z")

</div>

It would be too invasive on our part to write to another software system’s store without explicit instruction and use of a contract, which is what we do for our Maven plugin’s install task.

Also, the physical layout of Maven’s repository would not support the characteristics and features of our cache.

In summary, there are several reasons why using maven’s cache would be a bad thing for Gradle and one good reason (disk space optimization) and one debatable (state sync between the two tools). It’s just not going to happen.

---

<div class="post-metadata">

**Author:** ![corneil](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/corneil/32/90_2.png) [@corneil](https://discuss.gradle.org/u/corneil)\
**Post date:** [October 27, 2014, 2:18pm UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/16 "2014-10-27T14:18:00Z")

</div>

It would be great to be able to say gradle installDependencies and all dependencies from local cache get copied to local maven repo. This way if I delete the gradle cache or want to use the same dependencies in a different project I don’t have to pay the penalty for downloading the artifacts.

---

<div class="post-metadata">

**Author:** ![bmuschko](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bmuschko/32/5458_2.png) [@bmuschko](https://discuss.gradle.org/u/bmuschko)\
**Post date:** [May 21, 2015, 5:10pm UTC](https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525/17 "2015-05-21T17:10:33Z")

</div>

@corneil You can now write this operation yourself by using the Artifact Query API (\>= Gradle 2.3) which gives you direct access to the resolved artifacts as well as the metadata files.
