Why isn't gradle using ~/.gradle?

Both gradle and gradlew are silently refusing to use ~/.gradle to cache downloaded files.

When gradlew runs from Jenkins, it downloads the gradle zip to the workspace directory rather than ~jenkins. Then once gradle proper starts running, it caches all downloaded jars in workspace/.gradle but not in ~/.gradle. This is a problem because Jenkins is configured to wipe the workspace directory clean before each build.

When I run gradlew from my own machine, everything behaves as I expect – files are cached in my home directory. Here’s a short excerpt from the Jenkins log:

10:20:56
HOME=/home/jenkins
10:20:56
JAVA_HOME=/jenkins/tools/hudson.model.JDK/1.7_07
10:20:56
LOGNAME=jenkins
10:20:56
PWD=/jenkins/workspaces/Gradle-Continuous
10:20:56
USER=jenkins
[...]
10:20:56
[Gradle-Continuous] $ /jenkins/workspaces/Gradle-Continuous/gradlew -Djenkins.user.for.email=******** -Djenkins.password.for.email=******** -d autobuild
10:20:56
Downloading http://services.gradle.org/distributions/gradle-1.6-bin.zip
10:21:03
...[...]
10:21:03
Unzipping /jenkins/workspaces/Gradle-Continuous/wrapper/dists/gradle-1.6-bin/72srdo3a5eb3bic159kar72vok/gradle-1.6-bin.zip to /jenkins/workspaces/Gradle-Continuous/wrapper/dists/gradle-1.6-bin/72srdo3a5eb3bic159kar72vok

There’s nothing funny in gradle-wrapper.properties:

#Tue Jul 02 16:32:52 UTC 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.6-bin.zip

And ~jenkins is writable by Jenkins:

$ ls -ld ~jenkins
drwxr-xr-x 11 jenkins jenkins 4096 Jul
2 11:13 /home/jenkins

I dug into the gradlew source, and it looks like it should be using user.home as I expect. I tried adding

println("user.home = " + System.properties['user.home'])

to my top-level build.gradle, and it printed /home/jenkins as expected.

I just tried some different search terms and found my answer: http://forums.gradle.org/gradle/topics/local_cache_takes_up_4_gb and the contentious https://github.com/jenkinsci/gradle-plugin/pull/12 .

Hi,

AFAIK this is a somewhat unpractical change in the last jenkins gradle plugin. It sets the home directory to the workspace. Last time I’ve looked it will be reverted in the next version of the plugin (or made configurable). Alternatively downgrade to version 1.20 which is still ok.

Cheers,

Ric