Ilia
Ilia

Reputation: 341

gradle task definition syntax

gradle docs say that the way I declare task in my build.gradle file should be

task greeting(type: GreetingTask) {
    greeting = 'greetings from GreetingTask'
}

can anybody explain to me what happens here in terms of groovy syntax? I know that {} block is the closure and it can be passed as a parameter to the function but I still don't get what's happening here

Upvotes: 2

Views: 164

Answers (1)

JB Nizet
JB Nizet

Reputation: 691943

The task keyword is a gradle-specific stuff. It's not standard groovy, but something added by gradle using an AST transformation, in order to make the DSL simpler. It's basically equivalent to

project.tasks.create([name: 'greeting', type: GreetingTask]) { ... }

See https://discuss.gradle.org/t/how-to-translate-task-keyword-in-dsl-into-groovy-call/7243

Upvotes: 4

Related Questions