How can the Git command be executed on Windows through Gradle?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 13:24:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!