Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set gradle temporary directory to SSD

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)

like image 671
tomsv Avatar asked Apr 05 '14 12:04

tomsv


People also ask

How do I move a .gradle folder to my D drive?

In Windows File Explorer move the . gradle folder to the new location. Move by either by dragging and dropping while holding the Shift key, or using the File Explorer context menu (normally right-click) and selecting cut, and then paste to the new location.

How do I change the gradle path in Android Studio?

To change its path go to this path File > Settings... > Build, Execution, Deployment > Gradle In the Global Gradle settings Change Service directory path to what you want. Save this answer.


2 Answers

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.

like image 68
Peter Niederwieser Avatar answered Sep 28 '22 17:09

Peter Niederwieser


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
}
like image 27
kyb Avatar answered Sep 28 '22 17:09

kyb