Delegation to TaskInputs/TaskOutputs

This is a bit of a Am I stupid or what kind of question.

Class FooTask extends DefaultTask {

  void this_works(Closure cfg) {
    inputs.with(cfg)
  }

  void this_does_not_work(Closure cfg) {
    def cfg2 = cfg.clone()
    cfg2.delegate = inputs
    cfg2()
  }
}

Given the above task and something like

// Let's just assume /some/dir[12] exist and have children files
task foo(type:FooTask)  {

  // This will happily populate task inputs
  this_works {
    dir '/some/dir1'
  }

  // But trying to do this will not add anything
 this_does_not_work {
    dir '/some/dir2'
  }
}

That is pretty basic Groovy (and Gradle plugin stuff), yet for some reason delegation does not work for TaskInputs or TaskOutputs (at least in Gradle 2.0 it does not). Just wondering what is going on here.

In this case dir might be declared elsewhere. Caling Project.configure() does one additional step, it sets the closure’s resolve strategy to delegate first.

cfg2.resolveStrategy = Closure.DELEGATE_FIRST

Grrr… that’s it.

Setting cfg2.resolveStrategy=Closure.DELEGATE_FIRST solved it.

Thanks Mark.