gpt4 book ai didi

android - 在 Android build.gradle 中使用 `git describe --match`

转载 作者:行者123 更新时间:2023-11-29 01:04:51 26 4
gpt4 key购买 nike

在 Gradle 中获取与传入 git describe 的 glob 相匹配的最新 git 标签时遇到问题。它在终端中工作正常。

我尝试了以下方法:

project.ext.releaseVersionName = "git describe --match \'[0-9]*.[0-9]*.[0-9]*\' --abbrev=0 --tags".execute().text.trim()

def getReleaseVersion = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'bash', '-c', 'git', 'describe', '--match "[0-9]*.[0-9]*.[0-9]*"', '--abbrev=0', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
catch (ignored) {
return null
}
}

但是两者都返回空字符串。如果我没有匹配项,那么一切正常。我认为是 glob 导致了问题。

最佳答案

通过将整个 '--match "[0-9]*.[0-9]*.[0-9]*"' 放在单引号中,您基本上是通过了带有整个字符串的选项。您真正想要的可能是通过参数 [0-9]*.[0-9]*.[0-9]* 传递选项 --match >。因此,您应该拆分该参数,以便您的 commandLine 变为:

commandLine 'git', 'describe', '--match', '[0-9]*.[0-9]*.[0-9]*', '--abbrev=0', 'HEAD'

或者,您可以将 --match 参数切换为 --arg=value 语法,即使用 --match=[0-9]* .[0-9]*.[0-9]* 就像您对 --abbrev=0 所做的那样。

我已经根据评论删除了 'bash', '-c' 部分。如果要使用 'bash', '-c',则其余部分应该是一个字符串,因为它将作为 -c 参数的值庆典

关于android - 在 Android build.gradle 中使用 `git describe --match`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48011944/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com