问题
So I have the following code snippet:
def getVersion = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags'
standardOutput = stdout
}
return stdout.toString().trim()
}
and whenever I call getVersion(), I get the following error:
* What went wrong:
A problem occurred evaluating root project 'ForgeWorkspace'.
> Process 'command 'git'' finished with non-zero exit value 128
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 6.442 secs
On my MacBook Pro I've never encountered this issue, but do on Windows. Any help is greatly appreciated!
回答1:
@RaGe is almost correct. Since you indeed need to use the Windows Command Prompt (cmd) to have the OS search the git executable in the system path, the entire git command should be passed as one argument that follows the /c switch (which means 'execute command').
So the following should work:
commandLine 'cmd', '/c', 'git describe --tags'
回答2:
On windows, the first two arguments of commandLine should be cmd and /c
//on windows:
commandLine 'cmd', '/c', 'git'...
See here.
来源:https://stackoverflow.com/questions/34361298/how-can-the-git-command-be-executed-on-windows-through-gradle