I just run into idea of using RAMdisk for compilation results 1
How to use RAMdisk with Gradle?
I guess it is worth moving .gradle
and build
folders into RAMdisk.
Just for completeness, here's how I configured Gradle (and thereby also Android Studio) on Ubuntu 14.04 to always build to RAM disk:
My ~/.bashrc
contains this line in the end:
. ~/bin/mkramdisk # Setup personal RAM disk on login.
My ~/bin/mkramdisk
is listed below. I suppose you could omit this script and simply use e.g. /dev/shm/${System.env.USER}/gradle-builds
in the following step, but I like having a general RAM disk for other purposes as well, for instance I use it for my $TMP
so here goes:
# Setup personal RAM disk.
# This script should be sourced, hence the missing +x flag.
# Source it from e.g. from ~/.bashrc or run it from crontab
# at @reboot event (doesn't work with encrypted homedir btw.)
export RAMDISK=$HOME/tmp/ramdisk
if [ ! -d $RAMDISK ]; then
[ -d /dev/shm/$USER-ramdisk ] || install -vd /dev/shm/$USER-ramdisk -o $USER -m 700
[ -d ~/tmp ] || mkdir -v ~/tmp
[ -L ~/tmp/ramdisk ] || ln -vs /dev/shm/$USER-ramdisk ~/tmp/ramdisk
fi
# Use personal RAM disk for $TMP.
export TMP=$RAMDISK
NOTE to Macintosh users: It seems you can modify mkramdisk
to instead contain this command to make it work on your system.
To finally answer the question, my ~/.gradle/init.gradle
is this:
println "Loaded personal ~/.gradle/init.gradle"
gradle.projectsLoaded {
rootProject.allprojects {
buildDir = "${System.env.RAMDISK}/gradle-build/${rootProject.name}/${project.name}"
println "BUILDING TO RAMDISK: buildDir=$buildDir"
}
}
Remove debug println
statements as you see fit.
in root build.gradle
allprojects {
buildDir = "/path/to/build/${rootProject.name}/${project.name}"
}
See also
and docs https://gradle.org/docs/current/userguide/writing_build_scripts.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With