如何创建始终运行的gradle任务? [英] How to create gradle task which always runs?
问题描述
我可能会忽视某些相当核心/显而易见的事情,但是我怎样才能创建一个总是为每个任务/目标执行的任务?
我可以做例如:
任务someTask<< {
println我有时运行
}
println我总是运行
但是,在任务中保留始终运行的部分会更加可取。
最接近的是:
任务someTask<< {
println我有时运行
}
println我总是运行
void helloThing(){
printlnI总是也跑,你好?
helloThing()
因此,使用方法是一个'好'的解决方案,但我希望有一种方法来专门指定/重用任务。
希望有人有办法做到这一点。 :)
假设目标是打印系统信息,您可以只是始终在配置阶段打印信息一个任务声明),并且有一个虚拟任务 systemStatus
,它什么都不做(因为信息总是打印出来)。或者你可以把它作为一个常规任务来实现,并且通过添加:systemStatus
作为 gradle的第一项来确保任务总是运行。 startParameter.taskNames
(一个字符串列表),它模拟总是输入 gradle:systemStatus ...
的人。或者,您可以利用诸如 gradle.projectsLoaded {...}
之类的钩子在那里打印信息。
I'm likely overlooking something pretty core/obvious, but how can I create a task that will always be executed for every task/target?
I can do something like:
task someTask << {
println "I sometimes run"
}
println "I always run"
But it would be much more desirable to have the always running part in a task.
The closest I've come is:
task someTask << {
println "I sometimes run"
}
println "I always run"
void helloThing() {
println "I always run too. Hello?"
}
helloThing()
So, using a method is an 'ok' solution, but I was hoping there'd be a way to specifically designate/re-use a task.
Hopefully somebody has a way to do this. :)
Assuming the goal is to print system information, you could either just always print the information in the configuration phase (outside a task declaration), and have a dummy task systemStatus
that does nothing (because the information is printed anyway). Or you could implement it as a regular task, and make sure the task always gets run by adding ":systemStatus"
as the first item of gradle.startParameter.taskNames
(a list of strings), which simulates someone always typing gradle :systemStatus ...
. Or you could leverage a hook such as gradle.projectsLoaded { ... }
to print the information there.
这篇关于如何创建始终运行的gradle任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!