How to download and cache artifacts into local Maven Repository from Gradle
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:
repositories {
mavenLocal()
...
}
You can publish artifacts into the local Maven repository by putting into your build.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.
I want the dependencies to be stored in the local Mavan Repo than the Gradle local repo
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.
Are the cached Jars moved to the local maven repo when installed or just the build artifacts?
Only the build artifacts (i.e. what your gradle project built)
indeed, this is something I am missing. Are there any plans to support the download to the local maven repository?
Thatâs not something thatâs planned at this point, and not likely to be anytime soon.
I think this is indeed important! I have to take so long to redownload the artifacts which I have downloaded.
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.
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.)
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.
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.
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.)
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.
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.
@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.