The first syntax defines the task and provides some code that will be executed when the task is performed. The second syntax defines the task and provides some code for the immediate execution of the task. For example:
task build << { println 'this executes when build task is executed' } task build { println 'this executes when the build script is executed' }
In fact, the first syntax is equivalent:
task build { doLast { println 'this executes when build task is executed' } }
So, in your example above for syntax A, the description does not appear in gradle -t, because the code that sets the description does not execute before the task completes, which does not happen when gradle -t is started.
For syntax B, the code executing ant.echo () is run for every gradle call, including gradle -t
To provide both an action for execution and a description of the task, you can perform any of the following actions:
task build(description: 'some description') << { some code } task build { description = 'some description'; doLast { some code } }
Adam Murdoch May 05 '10 at 5:12 a.m. 2010-05-05 05:12
source share