Hi Adam,

On May 3, 2009, at 11:05 AM, Adam Murdoch wrote:

Hi,

I'd like to get some feedback on the new task definition DSL I've added to trunk.

The changes replace the createTask() method with a keyword style syntax for use in build scripts, and a groovy-ish API for use elsewhere.

The new syntax is:

task <task-name> [(option...)] [ { action } ]

Some examples:

task aTask  // was createTask('aTask')

task aTask { do stuff } // was createTask('aTask') { do stuff }

task aTask(type: Copy, dependsOn: someOtherTask) // was createTask('aTask', type: Copy, dependsOn: someOtherTask)

task aTask(dependsOn: anotherTask) { do stuff } // you can figure this one out

More examples in the user guide at 
http://gradle.org/userguide/latest/tutorial_using_tasks.html

This looks very nice. Task declarations are the bread and butter of the build scripts. Making the declaration of them as convenient and readable and nice as possible is important. I'm very happy with this.



One thing to note is that this syntax works only for statements. It does not work for expressions. That is, you can't do:

Task someVar = task aTask

For one thing, this isn't actually valid groovy. It would have to look like:

Task someVar = task(aTask)

Groovy user's are used to the parentheses issue. Sometimes you need them and sometimes not. We have the same issue in our dependencies declaration. You need parentheses if you use the map notation and have multiple map arguments.

which defeats the purpose, I think. It also looks a lot like a call to the Project.task() method, which is confusing, I think:

Task someVar = task('anExistingTask')

The project task method is rarely used in a build script. You need it if your task names don't obey to valid Groovy variable names or if there is some shadowing going on. So why not renaming the Project.task method to Project.getTask. Then we could provide task(taskName) for the usage in statements and in a fluent API manner without causing confusion. The use cases for this are not common but also not extremely exotic. And you wouldn't have to fall back to a completely different syntax.

- Hans



or worse:

taskName = 'anExistingTask'
Task someVar = task(taskName) { configure the task }

For both these reasons, I've limited the syntax to statements.

For defining a task in an expression, or in classes outside the build script, you can use the API on TaskContainer:

tasks.add(name: 'aTask') // replaces createTask('aTask')
tasks.add(name: 'aTask') { do something }
tasks.add(name: 'aTask', type: Copy)

Finally, Project.createTask() will be deprecated in the 0.6 release, and removed some time after the release.

Comments?


Adam


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email



--
Hans Dockter
Gradle Project lead
http://www.gradle.org





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to