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.

Either


 of the above code works as "expected" when using the "<<" form to
 ensure it is only engaged at execution time:

      task(taskName) << {


Should addRule work for configuration time tasks?  If not, then a 
better detection mechanism and set of error messages would be useful.

It


 appears that addRule gets called twice if a configuration time task is 
specified, and that second pass is whether "interesting" things happen.

(Tried to send this to the dev list and it bounced back saying I wasn't 
subscribed, even though I subscribed and followed the instructions on the 
confirmation email)

-Spencer


      

Reply via email to