首页 > 解决方案 > How to run an exe file from gradle build during execution phase (Windows)

问题描述

I need to run an exe file during the execution phase of the build.

I know I can define something like this:

task executeScript(type:Exec) {
    println 'Executing script...'
    commandLine './script.sh'
}

But this is running the script during configuration phase. I tried to wrap the code with a doLast block:

task executeScript(type:Exec) {
    doLast {
        println 'Executing script...'
        commandLine './script.sh'
    }
}

But this return an error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyAssets'.
> execCommand == null!

What should I do?

标签: androidwindowsgradle

解决方案


我知道我可以定义这样的东西:

task executeScript(type:Exec) {
    println 'Executing script...'
    commandLine './script.sh'
}

您的第一次尝试实际上是正确的。您的消息将在配置阶段打印,因为在配置println任务时会评估调用executeScript,但脚本本身在任务执行之前不会执行。

如果您想在任务执行之前打印一条消息,请尝试以下操作:

task executeScript(type:Exec) {
    commandLine './script.sh'
    doFirst {
        println 'Executing script...'
    }
}

推荐阅读