在gradle中运行shell命令,但不在任务中运行 [英] Run shell command in gradle but NOT inside a task
本文介绍了在gradle中运行shell命令,但不在任务中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任务myTask(类型:Exec){
可执行文件something.sh
...(很多其他的东西)
args-t
args ext.target
}
任务doIt {
myTask.ext.target =/ tmp / foo
myTask.execute();
myTask.ext.target =/ tmp / gee
myTask.execute();
}
当我启动时,我想我可以用不同参数运行myTask doIt方法。但是只有在脚本第一次执行时,因为Gradle需要注意一个任务只运行一次。
如何重写myTask,以便我可以多次调用它?不必将它作为单独的任务。
解决方案
您可以执行以下操作:
def doMyThing(String target){
exec {
executablesomething.sh
args-t,目标
}
}
任务doIt {
doLast {
doMyThing(/ tmp / foo)
doMyThing(/ tmp / gee)
}
}
这里 exec
不是一项任务,它是 Project.exec()
方法。
What I currently have is:
task myTask (type : Exec) {
executable "something.sh"
... (a lot of other things)
args "-t"
args ext.target
}
task doIt {
myTask.ext.target = "/tmp/foo"
myTask.execute();
myTask.ext.target = "/tmp/gee"
myTask.execute();
}
With this I thought I could run "myTask" with different parameters when I start "doIt". But only the first time the script is executed because gradle takes care that a task only runs once. How can I rewrite the "myTask" so that I can call it more than once? It is not necessary to have it as a separate task.
解决方案
You can do something like the following:
def doMyThing(String target) {
exec {
executable "something.sh"
args "-t", target
}
}
task doIt {
doLast {
doMyThing("/tmp/foo")
doMyThing("/tmp/gee")
}
}
The exec
here is not a task, it's the Project.exec()
method.
这篇关于在gradle中运行shell命令,但不在任务中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文