【问题标题】:How to execute more than one shell scripts in a task in gradle file如何在 gradle 文件中的一个任务中执行多个 shell 脚本
【发布时间】:2019-04-29 04:30:05
【问题描述】:

我是 gradle 新手,我有一个场景,我需要在 gradle 的单个任务中执行 2 个 shell 脚本。

我尝试了以下,但它没有执行 script1.sh 任务。

task downloadtheArtifacts(type: Exec) {
    commandLine './script1.sh'
    commandLine './script2.sh'
}

请告诉我如何解决这个问题?

【问题讨论】:

    标签: java shell gradle scripting build.gradle


    【解决方案1】:

    试试看:

    task downloadtheArtifacts {
        doLast {
            exec {
                commandLine './script1.sh'
            }
            exec {
                commandLine './script2.sh'
            }
        }
    }
    

    【讨论】:

    • 我在没有 doLast 的情况下也尝试了上面的代码,它有效。在这种情况下我们需要放置 doLast 还是 doFirst ?
    • 您应该使用doLast,否则脚本将在您每次在此项目上调用 Gradle 时执行,而不仅仅是在执行此特定任务时。这与没有任务定义的情况相同(只是 exec 闭包,试试吧!)。
    猜你喜欢
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 2015-05-11
    • 1970-01-01
    相关资源
    最近更新 更多