On 3/04/10 10:05 PM, Spencer Allain wrote:
tasks.addRule("MyRule") { String taskName ->
    if (!taskName.equals('taskName')) {
      println taskName
      task(taskName) {
        println taskName + " executed!"
      }
    }
    else {
      println 'Huh?'
    }
}

gradle -q billy

billy
Huh?
billy executed!

FAILURE: Could not determine which tasks to execute.

* What went wrong:
Task 'billy' not found in root project 'tmp13'.

Now changing it to the below form (that doesn't check for the special name of taskName)

tasks.addRule("MyRule") { String taskName ->
  println taskName

  task(taskName) {
    println taskName + " executed!"
  }
}

the output becomes:

billy
taskName
taskName executed!

FAILURE: Build failed with an exception.

* What went wrong:
Cannot add task ':taskName' as a task with that name already exists.

Not sure what exactly is causing this behavior at configuration time instead of execution time.


The task DSL implementation was a bit over-eager and was 'stealing' the task definition. For something like:

{ String taskName ->
    task(taskName) { // do stuff }
}

the DSL should leave this definition alone, and let project.task(String, Closure) do the work. However, the DSL was transforming the above into

{ String taskName ->
    task('taskName') { // do stuff }
}

which is causing what you are seeing above. I've fixed this in trunk.


--
Adam Murdoch
Gradle Developer
http://www.gradle.org

Reply via email to