Gradle Cache Location or Gradle local repository is the location where Gradle maintain its cache, which includes all dependencies Gradle downloads from repositories when we build any project, for reusing in the next times we run the build again.
1. Gradle Cache Location
Gradle uses $USER_HOME/.gradle as the default directory to store its local cache.
So, if you’re in Linux system: ~/.gradle
If you’re in Windows, it should be: C:\Users\[Your_Username]\.gradle
For example,
In my Windows 10, the location is: C:\Users\geeksgn\.gradle
In my Ubuntu 16.04, the location is: /home/geeksgn/.gradle
2. Change Gradle Cache Location
We can change the Gradle Cache Location to some other directory by setting the environment variable GRADLE_USER_HOME
For example,
2.1. In Linux
Edit the /etc/profile by any editor such as: vim, nano, etc and append following line at the end of the file.
1 |
export GRADLE_USER_HOME=/opt/gradle |
Then, issue below command make the environment variables effectively.
1 |
source /etc/profile |
2.2. In Windows
2.2.1. In Windows 7, right click My Computer and select Properties > Advanced.
In Windows 8, Windows 10, go to Control Panel > System > Advanced System Settings.
2.2.2. Under System Variables, click New
2.2.3. In the Variable Name field, enter GRADLE_USER_HOME
2.2.4. In the Variable Value field, enter your desire folder, for ex: D:\Misc\Gradle
2.2.5.Click OK
2.3. Verification
You can verify again by open a new terminal, go to any Gradle project and run some Gradle tasks. Then check the new location where you have just set for the GRADLE_USER_HOME variable.
3. Summary
We have just learned about Gradle Cache Location or Gralde local repository which is the location where Gradle store its libraries, dependencies during the builds of project. We also learned about how to change the default Gradle cache location to other directory by setting the environment variable.
Below are other articles related to Gradle topic, if you’re interested in, please access the following links:
Install Gradle on Ubuntu 16.04 LTS (Xenial Xerus)
Specify The Build File in Gradle
Convert Maven POM File to Gradle Build File
Using Gradlew, The Gradle Wrapper