I am wondering a little about when the closure runs when you are defining a task rule?
For example:
tasks.addRule(“Pattern: ping”) { String taskName ->
if (taskName.startsWith(“ping”)) {
task(taskName) << {
println "Pinging: " + (taskName - ‘ping’)
}
}
}
When doing this inside a plugin, I came to the conclusion that it became quite handy to define more than just one task, and to work with the task graph to set up dependencies between tasks I wanted to execute in a certain order.
ie.
tasks.addRule(“Pattern: ping”) { String taskName ->
if (taskName.startsWith(“ping”)) {
def someTask = task(‘someTask’) << {
println “hello”
}
def myRule = task(taskName) << {
println "Pinging: " + (taskName - ‘ping’)
}
myRule.dependsOn someTask
}
}
Is that a hack or is it perfectly fine to carry on doing that?
With this pattern it becomes quite easy to see both the configuration phase and execution phase code of a particular task inside a plugin, but then it dawned on me that I don’t actually know when the addRule() code runs, is it initialisation or configuration?