Aggregating TaskOutput FileCollection(s) into a CopySpec with builtBy

TL;DR: How do I make a CopySpec depend on a task.

I have a task (GithubPages) which has a CopySpec.
I have a set of tasks (Javadoc) which generate files.
I’m trying to find a way of aggregating all the output filesets of the Javadoc tasks into the GithubPages CopySpec.
The extra magic is that I want each output fileset to have a builtBy referring to the relevant task.

Now, I think I can wrap the output files of the task into a FileCollection with a builtBy using: project.files(task.getOutputs().getFiles()).builtBy(task)

But repeatedly calling myCopySpec .from( project.files(task.getOutputs().getFiles()).builtBy(task) ) .into(task.getName()) does not seem to work. I suspect this is because AbstractFileResolver only honours FileCollection if the paths array is of length 1?

My second idea was to wrap each fileset in its own CopySpec and use CopySpec.with() but I can’t construct a “blank” CopySpec because I can’t see FileResolver in the public API.

My third idea was that CopySpec should have a builtBy, but it hasn’t.

Any ideas? Thank you all.

P.S. it would be really nice if Task.getOutputs().getFiles() automatically had a builtBy(t), then this all wouldn’t be an issue.

from() already does that for you.

Have you tried:


I did, and it doesn’t seem to work.

The code is here:

and if I change it to:

github.getPages().from(docAggregateTask, new Closure<Void>(StdProjectPlugin.this) {

and remove the dependsOn below, and run ./gradlew clean publishGhPages it doesn’t run aggregateJavadoc first.

1 Like

Ah, it’s an issue with the publishGhPages task. It uses project.copy {} which won’t add any dependencies to the publish task. You’ll have to use dependsOn right now.

It looks like in master they’re moving to splitting the “publish” and “prepare” steps of that task into separate tasks. If they made the ‘prepare’ a Sync/Copy task, it would work as I suggested.

I’d ping @ajoberstar and open an issue on GH for the plugin.

Thank you. I will do as you suggest, while making this post at least 20 characters long so that I at least get to say thank you.