On 28/11/2010, at 9:48 AM, Steven Devijver wrote:

> Hey,
> 
> I have these tasks:
> 
> def my_dir = "test_dir"
> 
> task A(type: Delete) {
>       delete = my_dir
> }
> 
> task B(dependsOn: "A") {
>       outputs.upToDateWhen {
>               file(my_dir).exists()
>       }
>       doFirst {
>               ant.mkdir dir: my_dir
>       }
> }
> 
> I was assuming that when a task is up-to-date its dependencies wouldn't be 
> executed. However, B is never up-to-date because the upToDateWhen closure is 
> executed before B is executed but not before A is executed. A is always 
> executed regardless of B's outputs.
> 
> Is there a way of avoiding B's dependencies are executed when its outputs are 
> up-to-date?

You would declare the inputs and outputs of each dependency. There's no good 
way (yet) for Gradle to know whether or not a dependency affects the 
configuration or inputs of B, without them declaring something about what they 
do.

In your example above, 'A' doesn't really look like a dependency of 'B'. It 
looks more like the first part of the work of 'B', so the example might be 
better done as:

task B {
    outputs.upToDateWhen { .... }
    doFirst {
        delete my_dir
        ant.mkdir dir: my_dir
    }
}


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz

Reply via email to