如何通过Gradle在Windows上执行Git命令? [英] How can the Git command be executed on Windows through Gradle?

查看:414
本文介绍了如何通过Gradle在Windows上执行Git命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有以下代码片段:

So I have the following code snippet:

def getVersion = { ->
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'describe', '--tags'
        standardOutput = stdout
    }
    return stdout.toString().trim()
}

,每当我打电话 getVersion(),出现以下错误:

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

在我的MacBook Pro上,我从未遇到过此问题,但在Windows上却遇到过。

On my MacBook Pro I've never encountered this issue, but do on Windows. Any help is greatly appreciated!

推荐答案

@RaGe几乎是正确的。由于您确实确实需要使用Windows命令提示符(cmd)来使操作系统在系统路径中搜索git可执行文件,因此应将整个git命令作为 / c 开关(表示执行命令)。

@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'

这篇关于如何通过Gradle在Windows上执行Git命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆