These three forms to define a task in build.gradle seem identical. All of them call org.gradle.api.internal.project.DefaultProject#task(java.lang.String, groovy.lang.Closure)
, but really I can't understand how the second and the third one can work.
def myAction = {t -> println "${t.name} [${t.class.name}]"}
task('myTaskA') {task ->
group = 'MyTasks'
description = name
doLast myAction
}
task myTaskB {task ->
group = 'MyTasks'
description = name
doLast myAction
}
task myTaskC() {task ->
group = 'MyTasks'
description = name
doLast myAction
}