[GRADLE-366] Gradle should make it easy to determine the full path to the build.gradle file Created: 22/Jan/09 Updated: 04/Jan/13 Resolved: 28/Feb/09 |
|
Status: | Resolved |
Project: | Gradle |
Affects Version/s: | None |
Fix Version/s: | 0.6 |
Type: | New Feature | ||
Reporter: | Jon Cox | Assignee: | Hans Dockter |
Resolution: | Fixed | Votes: | 0 |
Issue Links: |
|
Description |
Sometimes, it's very useful for scripts to know their own directory; however, For this & other reasons, I'd love it if Gradle would have some build.properties.buildScriptDirName == cannonicalized path to dir containing build.gradle file (or whatever it's named) Eventually, I hope that Groovy's "script.name" property gets sorted out on all platforms [1] Often the directory is wanted, and "script.name" is the [2] The ugly-but-backward-compatible hack I came up with on Linux: For more details on Groovy's current problems with script.name, see: |
Comments |
Comment by Hans Dockter [ 26/Jan/09 ] |
We provide this already: project.projectDir project.build.startParameter.buildFileName Does this solve your issue? |
Comment by Jon Cox [ 26/Jan/09 ] |
Yes it does – thanks. The string "projectDir" appears once in italics in table 10.3, It's good to maintain a distinction between the |
Comment by Jon Cox [ 26/Jan/09 ] |
Wait a second.... I don't think projectDir actually works the way I'd expect. createTask("foobar") { println "user dir: " + System.getProperty("user.dir") println "project dir: " + this.projectDir println "build file: " + this.build.startParameter.buildFileName } Now let's 'cd' to '/' and run the command line: % gradle -q -b /tmp/xxx.gradle foobar What we get out is: user dir: / project dir: / build file: /tmp/xxx.gradle Notice that the user executed the command from '/' so Groovy sets The next line differs from what I'd expect to see: Is the current behavior of "this.projectDir" a bug? The final line is not quite what I would have expected % cd /tmp % gradle -q -b xxx.gradle foobar Think about what you'd like Gradle to do if someone said something % cd / % gradle -q -b /tmp/../tmp/xxx.gradle foobar Currently, it emits: user dir: / project dir: / build file: /tmp/../tmp/xxx.gradle That seems a bit wonky – if the build file is going to be reported as If you have a chance, see also: http://jira.codehaus.org/browse/GROOVY-1642 |
Comment by Hans Dockter [ 26/Jan/09 ] |
Gradle has two command line options related to this, -p and -b. This: gradle -q -p /tmp - b xxx.gradle foobar should lead to the output. user dir: / project dir: /tmp build file: xxx.gradle The -b property was intended to specify the build file name, not the path. It was assumed that the build file lives in the project root dir. So my first intention was to see your example as a Gradle bug in that it accepts an illegal option argument. But on the other hand why not allowing to specify a build file path separate from the project dir. Then we have two other bugs. The -b property should be described as 'assign build file name, and the start parameter property should be called buildFile. And the latter should not be of type String but of type File and would be normalized at construction time. I have filed: http://jira.codehaus.org/browse/GRADLE-368 This will also solve Gradle-366. |
Comment by Adam Murdoch [ 28/Feb/09 ] |
I've added Project.buildFile, which returns a File whose path is the canonical path of the build file. I think this should solve the problem. |