Gradle execution of platform task

I upgraded to IDEA 13, and the following code in my build file stopped working (just to get the hash of the current git head for some logging):

def hashProc = "git rev-parse HEAD".execute();

def code = hashProc.waitFor();

def hash = hashProc.in.text

This was running fine in IDEA 12, and runs fine from the command line. In 13, the 'code' is 128. I guessed that there was a path problem, but using a full path to the git executable did not solve the problem.

3 comments
Comment actions Permalink

It seems, wrong working dir used for execution, try the following:

def hashProc = "git rev-parse HEAD".execute(null, projectDir);
def code = hashProc.waitFor();
def hash = hashProc.in.text

0
Comment actions Permalink

Yup, that fixed it. Seems like the working directory should be the same as the gradle file, or perhaps the project directory? Should a bug be logged?

0
Comment actions Permalink

yep, please, file the bug.
IntelliJ uses gradle tooling API for gradle invocation, which uses "System.getProperty("user.dir")" internally.
I think, it would be good to have an option to set user.dir in the gradle tooling API.

Anyway, I'd recommend to set required dir for process execution in build script - to have it independant of such issues .

E.g. the following execution even from command line will not work properly if you do not set right working dir:

$ cd ..
$ gradle -b gradle_project/build.gradle platformExecTask

0

Please sign in to leave a comment.