在Gradle中执行shell脚本 [英] Execute shell script in Gradle

查看:2229
本文介绍了在Gradle中执行shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gradle构建设置,在其开始,我想在准备我的环境的子目录中执行shellscript。

I have a gradle build setup at the beginning of which I want to execute a shellscript in a subdirectory that prepares my environment.

task build << {
}
task preBuild << {
    println 'do prebuild stuff:'
}
task myPrebuildTask(type: Exec) {
    workingDir "$projectDir/mySubDir"
    commandLine './myScript.sh'
}

build.dependsOn preBuild
preBuild.dependsOn myPrebuildTask

但是,当我通过调用 gradle myPrebuildTask 或简单的构建项目来执行任务时,会发生以下错误:

However, when I execute the task either by calling gradle myPrebuildTask or by simply building the project, the following error occurs:

> A problem occurred starting process 'command './myScript.sh''

不幸的是, 。

我也尝试过以下 - 同样的错误。

Unfortunately, thats all I get.
I have also tried the following - same error.

commandLine 'sh mySubDir/myScript.sh'



我使用Gradle 1.10(Android需要)在Windows上,在Cygwin shell中。任何想法?

I use Gradle 1.10 (needed by Android) on Windows, inside a Cygwin shell. Any ideas?

推荐答案

使用

commandLine 'sh', './myScript.sh'

您的指令码本身不是程序本身,这就是为什么你必须声明'sh'作为程序和脚本的路径作为参数。

your script itself is not a program itself, that's why you have to declare 'sh' as the program and the path to your script as an argument.

这篇关于在Gradle中执行shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆