[GRADLE-2956] native/jna dir creation does not honor {-g, --gradle-user-home} command line option Created: 19/Nov/13 Updated: 20/Apr/14 Resolved: 20/Apr/14 |
|
Status: | Resolved |
Project: | Gradle |
Affects Version/s: | None |
Fix Version/s: | 2.0-rc-1 |
Type: | Bug | ||
Reporter: | Gradle Forums | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Description |
I want complete control over where the files that gradle creates are going to go. Specifically, I do not want anything to end up in ~/.gradle To test this, I have created my own ~/.gradle dir, but made it read only: dr-xr-xr-x 2 rich engr 4096 2013-11-14 15:42 .gradle/ As expected, if I try to invoke gradle with minimal options, it fails: $ gradle-1.9-rc-3/bin/gradle -version FAILURE: Build failed with an exception.
This is effectively doing the same thing, but using the lower level java invocation rather than the gradle front-end script to give me more control in later examples: $ java -Dorg.gradle.appname=gradle -classpath gradle-1.9-rc-3/lib/gradle-launcher-1.9-rc-3.jar org.gradle.launcher.GradleMain -version FAILURE: Build failed with an exception.
The problem is that if I run it with the -g option, pointing to a dir where I do have access: $ ls -l /var/tmp | grep br-170 I get the same failure. Here, I'm showing it with a full stacktrace, which I have left out of the other examples for brevity: $ java -Dorg.gradle.appname=gradle -classpath gradle-1.9-rc-3/lib/gradle-launcher-1.9-rc-3.jar org.gradle.launcher.GradleMain -g /var/tmp/br-170 --stacktrace -version FAILURE: Build failed with an exception.
rich@rich2 [16:29:17 Thu Nov 14] ~/bugs/br-170 Using the alternate version of the option (--gradle-user-home) makes no difference: $ java -Dorg.gradle.appname=gradle -classpath gradle-1.9-rc-3/lib/gradle-launcher-1.9-rc-3.jar org.gradle.launcher.GradleMain --gradle-user-home /var/tmp/br-170 -version FAILURE: Build failed with an exception.
However, I can get it to work by passing this either as a java system property (gradle.user.home): $ java -Dgradle.user.home=/var/tmp/br-170 -Dorg.gradle.appname=gradle -classpath gradle-1.9-rc-3/lib/gradle-launcher-1.9-rc-3.jar org.gradle.launcher.GradleMain -version ------------------------------------------------------------ Build time: 2013-11-07 12:26:42 UTC Groovy: 1.8.6 rich@rich2 [16:30:33 Thu Nov 14] ~/bugs/br-170 or as an environment variable (GRADLE_USER_HOME): $ GRADLE_USER_HOME=/var/tmp/br-170 java -Dorg.gradle.appname=gradle -classpath gradle-1.9-rc-3/lib/gradle-launcher-1.9-rc-3.jar org.gradle.launcher.GradleMain -version ------------------------------------------------------------ Build time: 2013-11-07 12:26:42 UTC Groovy: 1.8.6 rich@rich2 [16:31:28 Thu Nov 14] ~/bugs/br-170 org.gradle.internal.nativeplatform.jna.JnaBootPathConfigurer.configure(File storageDir) uses as a basis for this the value that is passed to it. This in turn comes from the value passed to org.gradle.internal.nativeplatform.services.NativeServices.initialize(File userHomeDir) And that value is set by org.gradle.logging.internal.ConsoleConfigureAction.execute(), which calls org.gradle.StartParameter.getGradleUserHomeDir() That is just returning the member gradleUserHomeDir, which is set in the StartParameter constructor by org.gradle.initialization.BuildLayoutParameters.getGradleUserHomeDir() And that is just returning the member gradleUserHomeDir, which is set in by the BuildLayoutParameters constructor. So the problematic code might be in the constructor in src/core/org/gradle/initialization/BuildLayoutParameters.java Here are the complete contents of the constructor: public BuildLayoutParameters() { You can see that we first consider the system property (and StartParameter.GRADLE_USER_HOME_PROPERTY_KEY is set to "gradle.user.home"); and if that is not set, we next consider the environment variable "GRADLE_USER_HOME", and if that is not set, then we resort to StartParameter.DEFAULT_GRADLE_USER_HOME, which is set to ~/.gradle. Nowhere do we consider the command line flags. Or maybe that's fine, because if I look in org.gradle.wrapper.GradleWrapperMain, it does seem to have a method to parse this option: private static File gradleUserHome(ParsedCommandLine options) { and (in main()) add it to the system properties: File gradleUserHome = gradleUserHome(options); addSystemProperties(gradleUserHome, rootDir); Nevertheless, it doesn't seem to be working in this case. Maybe there's an ordering problem here, and the option just hasn't been parsed yet when the native services are initializing? I'm just guessing, this is the limit of how far I've debugged this. I initially saw this on older, released versions of gradle (1.3 and 1.7), and only tried the latest 1.9 rc to verify that it was still a bug before reporting it. At first I thought my problem was that I was just seeing this bug (which was fixed long ago): [1]https://github.com/wolfs/gradle/commi... And that 1.3 was just too old, but it appears that that fix went in much earlier than 1.3. |