Gradle store on local file system

Gradle

Gradle Problem Overview


How does Gradle store downloaded jar files on the local file system? Maven stores them in the .m2 directory under USER_HOME, but where does Gradle store them? I checked the .gradle folder there, but saw only compiled scripts.

Gradle Solutions


Solution 1 - Gradle

On Mac, Linux and Windows i.e. on all 3 of the major platforms, Gradle stores dependencies at:

~/.gradle/caches/modules-2/files-2.1

Solution 2 - Gradle

Gradle caches artifacts in USER_HOME/.gradle folder. The compiled scripts are usually in the .gradle folder in your project folder.

If you can't find the cache, maybe it's because you have not cached any artifacts yet. You can always see where Gradle has cached artifacts with a simple script:

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.google.guava:guava:12.0'
}

task showMeCache doLast() {
    configurations.compileClasspath.each { println it }
}

Now if you run gradle showMeCache it should download the dependencies into the cache and print the full path.

Solution 3 - Gradle

In Windows 10 PC, it is saved at:

C:\Users\%USERNAME%\.gradle\caches\modules-2\files-2.1\

Solution 4 - Gradle

Gradle's local repository folder is:

  • $USER_HOME/.gradle/caches/modules-2/files-2.1

Defined dependencies will be loaded from remote repositories into gradle's local repository folder. For each loaded file, gradle will be create a new folder named with md5 value of the original file (pom,jar,..). Full path for the dependency file is made up from :

  • groupid + artifactid + version + FILE_MD5_VALUE + FILE_NAME

If our defined dependency is:

  • compile 'org.springframework:spring-jdbc:4.3.4.RELEASE'

Then the library will be loaded into :

  • /$USER_HOME/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jdbc/4.3.4.RELEASE/42175d194cf6aa7c716c0887f30255e5c0a5262c/spring-jdbc-4.3.4.RELEASE.jar

Solution 5 - Gradle

In fact the cache location depends on the GRADLE_USER_HOME environment variable value. By default, it is $USER_HOME/.gradle on Unix-OS based and %userprofile%.\gradle on Windows.
But if you set this variable, the cache directory would be located from this path.

And whatever the case, you should dig into caches\modules-2\files-2.1 to find the dependencies.

Solution 6 - Gradle

If you want your dependency files to be in some specific folder you can simply use a copy task for it. For Eg.

task copyDepJars(type: Copy) {
  from configurations.compile
  into 'C:\\Users\\athakur\\Desktop\\lib'
}

Solution 7 - Gradle

I am on windows,

You should be able find the dependencies inside

$USER_HOME.gradle\caches\artifacts-24\filestore

Solution 8 - Gradle

Many answers are correct! I want to add that you can easily find your download location with

gradle --info build

like described in https://stackoverflow.com/a/54000767/4471199.

New downloaded artifacts will be shown in stdout:

Downloading https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-parent/2.1.7.RELEASE/spring-boot-parent-2.1.7.RELEASE.pom to /tmp/gradle_download551283009937119777bin

In this case, I used the docker image gradle:5.6.2-jdk12. As you can see, the docker container uses /tmp as download location.

Solution 9 - Gradle

You can use the gradle argument --project-cache-dir "/Users/whatever/.gradle/" to force the gradle cache directory.

In this way you can be darn sure you know what directory is being used (as well as create different caches for different projects)

Solution 10 - Gradle

I just stumbled onto this while searching for this answer. If you are using intellij, you can navigate to the file location, but opening the external lib folder in the project explorer, right clicking on the jar, and select Open Library Settings. enter image description here

Solution 11 - Gradle

In case it is an Android gradle project - you can find the android libraries below your $ANDROID_HOME/extras/android/m2repository folder

Solution 12 - Gradle

In android studio do the following steps to check the gradle downloaded jar file.

  1. Set project structure view to "Project"
  2. At bottom External library section available, expand it.
  3. Here you can see downloaded jar files. enter image description here

Solution 13 - Gradle

On my windows machine with "Buildship 2.0.2" plugin installed in eclipse, dependencies are stored :

$USER_HOME.gradle\caches\modules-2\files-2.1

Solution 14 - Gradle

It took me a while to realize this, hence the additional answer. Hopefully it can save folks time. Note that if you are running sudo gradle the dependencies may not be in your home directory, even if sudo echo $HOME returns /Users/<my-non-root-user>/. On my Mac, Gradle was caching the dependencies in /private/var/root/.gradle/caches/.

Solution 15 - Gradle

For my case, I was using an Ivy repository, and my Gradle dependencies were stored in ~/.ivy2/.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmanojpardeshi111View Question on Stackoverflow
Solution 1 - GradleHimanshu KhandelwalView Answer on Stackoverflow
Solution 2 - GradlerodionView Answer on Stackoverflow
Solution 3 - GradleHasan A YousefView Answer on Stackoverflow
Solution 4 - GradlenixView Answer on Stackoverflow
Solution 5 - GradledavidxxxView Answer on Stackoverflow
Solution 6 - GradleAniket ThakurView Answer on Stackoverflow
Solution 7 - Gradlemekbib.awokeView Answer on Stackoverflow
Solution 8 - GradleRoBeaToZView Answer on Stackoverflow
Solution 9 - GradleGraemeView Answer on Stackoverflow
Solution 10 - GradleAlper AktureView Answer on Stackoverflow
Solution 11 - GradlejoenssonView Answer on Stackoverflow
Solution 12 - Gradlechetan mekhaView Answer on Stackoverflow
Solution 13 - GradlenanosoftView Answer on Stackoverflow
Solution 14 - GradleentpnerdView Answer on Stackoverflow
Solution 15 - GradleentpnerdView Answer on Stackoverflow