gradle 命令行错误 "Cause: error=2, No such file or directory"

gradle commandLine erro "Cause: error=2, No such file or directory"

fedora 33,git安装在/usr/bin/git,添加在PATH

在 build.gradle 文件中,我提取了 git 哈希,以便稍后在构建 docker 图像标签时使用它。

def dockerImageVersion = { ->
  def stdout = new ByteArrayOutputStream()
  exec {
    commandLine "git describe --first-parent --abbrev=10 --long --dirty"
    standardOutput = stdout
  }
  return stdout.toString().trim()
}

jib {
  from {
    image = 'adoptopenjdk/openjdk11:ubi-minimal-jre'
  }
  to {
    image = "napa/activity-service"
    tags = ["${dockerImageVersion}", "latest"]
  }
  container {
    mainClass = "com.regrexx.user.events.InteractionEventsSinkVerticle"
    jvmFlags = ["-noverify", "-Djava.security.egd=file:/dev/./urandom"]
    user = "nobody:nobody"
  }
}


它给出错误:Cause: error=2, No such file or directory

即使我将命令更改为 commandLine 'echo hello',我仍然遇到同样的错误。

commandLine is expecting a List<String> 而不是空格分隔的字符串。

换句话说,Gradle 正在您的 PATH 中查找与整个字符串匹配的文件。它不解析空格来分隔命令和参数。期待已经完成。

尝试:

commandLine "git", "describe", "--first-parent", "--abbrev=10", "--long", "--dirty"