7

I am using android studio with gradle. When I build the app, I notice the spinning harddisk is working a lot, so I looked and saw that gradle is writing temporary files to the directory defined (in Windows (8.1)) the variable TEMP or TMP under my user.

Is there some way I can change the directory gradle uses as temporary directory without changing it for all other applications as well?

I would like to move the gradle temp dir to an SSD. (Bonus question: do you think this would significantly speed up gradle, that is currently very slow)

tomsv
  • 7,207
  • 6
  • 55
  • 88

2 Answers2

11

Try to set environment variable GRADLE_OPTS to -Djava.io.tmpdir=D:\some\dir\on\sdd, and GRADLE_USER_HOME to D:\other\dir\on\ssd. Also make sure that the project directory is on SSD.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • Do I have to reinstall gradle or do something else after I set these environment variables? Looks like cmd `SET GRADLE_OPTS="-Djava.io.tmpdir=P:\Gradle\temp"` didn't worked for me (folder is empty). But `SET GRADLE_USER_HOME="P:\Gradle\home"` works. – Kamil Oct 20 '22 at 11:46
  • It looks like I have now 2 gradles, one for Android Studio and from IntelliJ, because in Android Studio you have to do this https://stackoverflow.com/questions/32453793/can-i-move-the-android-studio-s-gradle-folder-to-other-disk – Kamil Oct 20 '22 at 11:55
2

In yourbuild.gradle

allprojects {
    buildDir = "c:/tmp/${rootProject.name}/${project.name}"     
}

Here is the full example code:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {


        buildDir = "c:/tmp/${rootProject.name}/${project.name}"
        repositories {

        }


    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Rafael T
  • 15,401
  • 15
  • 83
  • 144
kyb
  • 7,233
  • 5
  • 52
  • 105
  • Bad answer since the build dir is already on a "supposedly" SSD drive: "c:/tmp". Nothing in this answer mentioned how to relocate the gradle workdirs to a folder on an SSD drive. – Alex Sep 20 '21 at 12:54