86

I am starting to learn gradle. However when I am building Spring with Gradle; it downloads the dependency jars to

C:\Users\UserName\.gradle

Is there any way I can specify Gradle to download the dependency jars to a specific location? Just like I can specify repository location in Maven.

System information: Windows 7 64bit Gradle version 1.0

7 Answers 7

115

You can set the GRADLE_USER_HOME environment variable, gradle.user.home system property, or --gradle-user-home command line parameter.

4
  • 5
    Using GRADLE_USER_HOME is not work for me(gradle still load wrapper in to the old folder).Please help me how to run --gradle-user-home command line parameter.
    – UmAnusorn
    Commented Apr 5, 2014 at 3:44
  • this might be helpful for people new to gradle. I also need to re run ./gradlew installDist in my project folder to re-download everything to the new GRADLE_USER_HOME
    – emily
    Commented Jul 10, 2015 at 20:39
  • 4
    Setting the gradle.user.home property in the gradle.properties does not change the location.
    – Eric
    Commented Jul 25, 2016 at 19:39
  • This doesn't change the location but the GRADLE_HOME variable finds mention in all newly created/imported projects. So whatever folder you mention inside that variable will have the 'scum in the name of gradle' downloaded there. So it won't clog up your C anymore. What a shithole of a open source IDE this is!
    – user30478
    Commented Aug 31, 2018 at 18:45
11

On android studio just go to File > Settings > Build Execution, Deployment > Build Tools > Gradle > Service directory path choose directory what you want.

5
  • 3
    misleading answer
    – user30478
    Commented Aug 31, 2018 at 17:44
  • 1
    Work for me !!!! - on Android Studio 191.6010548-windows - Thank you very much Commented Mar 5, 2020 at 16:19
  • 3
    Worked for me after restarting the PC. Commented Jan 18, 2022 at 9:30
  • I tried this, it works only existing project. New project uses the default path. I found setting system environment variable GRADLE_USER_HOME as custom location, it did work, and setting panel shows the location as default.
    – iroiroys
    Commented Mar 16, 2022 at 8:09
  • This worked for me. What about visual code? Commented Aug 3, 2023 at 7:15
5

You can add following line to your gradle.properties:

systemProp.gradle.user.home=/tmp/changed-gradle
4

You can also try to go in eclipse at window ->preferences -> gradle and change the directory there

4

Steps:

  • Set the GRADLE_USER_HOME environment variable to new path
  • On android studio just go to File > Settings > Build Execution, Deployment > Gradle > Service directory path choose directory what you want.
  • Restart the PC (important step, no one mentioned this surprisingly)
2

If you want to run gradle tasks through IDE then: You can also set in intelliJ editor>File>settings:

IntelliJ editor

Then restart the IDE.

If you want to run gradle tasks through command line then you have to set GRADLE_USER_HOME in environment system variables. Then restart the pc as others also said.

0

If you are using gradle plugin in your eclipse and trying to import the gradle project than your gradle home is set to

C:\Users\UserName.gradle

In some cases your import build model will not work because of your user directory permission issue.

In this case you can copy your .gradle directory from below path

C:\Users\UserName\**.gradle**

paste into some directory where you have all permission and import the project.

In my case i moved my .gradle dir to z drive and than imported the project than made build model and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.