On 12 March 2011 22:19, Neil Chaudhuri <[email protected]> wrote:

> So I pretty much ripped this off verbatim from the Gradle Cookbook:
>
>
>
> task aggregateJavadoc(dependsOn: clean, type: Javadoc)   {
>
>   source subprojects.collect { project ->
>
>     project.sourceSets.main.allJava
>
>   }
>
>   destinationDir = file("${buildDir.absolutePath}/javadoc")
>
>   classpath = files(subprojects.collect { project ->
>
>     project.sourceSets.main.compileClasspath
>
>   })
>
> }
>
>
>
> When I run this, everything works as expected.
>
>
>
> But when I add << and run the following I get an error:
>
>
>
> task aggregateJavadoc(dependsOn: clean, type: Javadoc)  <<  {
>
>   source subprojects.collect { project ->
>
>     project.sourceSets.main.allJava
>
>   }
>
>   destinationDir = file("${buildDir.absolutePath}/javadoc")
>
>   classpath = files(subprojects.collect { project ->
>
>     project.sourceSets.main.compileClasspath
>
>   })
>
> }
>
>
>
> The error is
>
>
>
> Execution failed for task ':aggregateJavadoc'.
>
> Cause: Error validating task ':aggregateJavadoc': No value has been
> specified for property 'destinationDir'.
>
>
>
> Again, the task is precisely written as the other but with the << added
> only.
>
>
>
> I’ve read the docs pretty carefully on the lifecycle, and I am not able to
> figure out what the difference is between these two executions. I can see
> how something can fail in the configuration phase because not everything has
> been configured, but I have trouble understanding how anything can fail in
> the execution phase once everything is in place.
>
>
>
> Any insight into the difference between these two tasks is appreciated.
>

'<<' is an abbreviation for 'doLast'. The last case is equivalent to the
following code:

task aggregateJavadoc(dependsOn: clean, type: Javadoc)  {

  // Oops, no destinationDir specified here...

  doLast {

    source subprojects.collect { project ->

      project.sourceSets.main.allJava

    }

    destinationDir = file("${buildDir.absolutePath}/javadoc")

    classpath = files(subprojects.collect { project ->

      project.sourceSets.main.compileClasspath

    })

  }

}


The destinationDir assignment is in the wrong place. The Javadoc task needs
a destination directory to do its work. When you specify the destination
directory in a doLast closure, you are 'too late'.


cheers,

--L

Reply via email to