Gradle Exec - 如何记录命令行?

发布于 2025-01-19 04:44:52 字数 269 浏览 1 评论 0原文

我正在使用 Gradle 来构建我的项目。 构建文件包含多个 Exec 任务运行外部程序(shell 脚本和 Java Packager)。构建并不总是成功,我想找出原因。分析我得到的所有输出,我感觉很奇怪,Gradle 没有打印正在调用的命令。

如何让 Gradle 在开始执行之前打印命令行?

I am using Gradle to build my project.
The build file contains several Exec tasks to run external programs (shell scripts and the Java Packager). The build is not always successful and I want to find out why. Analyzing all the output I have it feels strange that Gradle does not print the command that is getting invoked.

How can I make Gradle print the commandline before it starts executing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

早乙女 2025-01-26 04:44:52

每当您调用gradle命令时,您都可以使用gradle的日志级别,

您都可以喜欢以下

./gradlew mytask --info //info logs
./gradlew mytask -s //to get stacktrace 

参考: https://docs.gradle.org/current/userguide/command_ine_interface.html#sec:command_line_logging
“ nofollow noreferrer”> html#sec:command_line_debugging

You can use log levels of gradle

whenever you invoke gradle command you can do like this

./gradlew mytask --info //info logs
./gradlew mytask -s //to get stacktrace 

Ref: 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

稍尽春風 2025-01-26 04:44:52

如果您希望在命令失败时始终看到错误:

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)")
        }
    }
}

In case you want to always see the error when the command fails:

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)")
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文