我正在使用 Gradle 来构建我的项目。 构建文件包含多个用于运行外部程序(shell 脚本和 Java Packager)的 Exec 任务。构建并不总是成功,我想找出原因。分析我拥有的所有输出,感觉很奇怪 Gradle 没有打印正在调用的命令。
如何让 Gradle 在开始执行之前打印命令行?
您可以使用gradle的日志级别
每当你调用 gradle 命令时,你都可以这样做
./gradlew mytask --info //info logs
./gradlew mytask -s //to get stacktrace
参考:https://docs.gradle.org/current/userguide/command_line_interface.html#sec:command_line_logging https://docs.gradle.org/current/userguide/command_line_interface.html#sec:command_line_debugging
如果您希望在命令失败时始终看到错误:
task myCommandLineTask(type: Exec) {
commandLine 'my_command.sh'
ignoreExitValue = true
standardOutput = new ByteArrayOutputStream()
doLast {
def exitCode = executionResult.get().exitValue
if (exitCode != 0) {
def result = standardOutput.toString()
logger.warn(result)
throw new GradleException("Failed to run command (exit code:$exitCode)")
}
}
}