Pattern for tasks which produce aggregated reports across multi-project build

Are there any patterns for writing tasks which operate across the SourceSets of multiple sub-projects within a multi-project build?

The specifics, if they help…

I use a number of annotations which indicate the level of support for packages, classes, methods, fields - @Internal, @Incubating, etc. As part of my release process I’d like to generate “reports” from these annotations. The actual collection and generation is done. However, at the moment it is done per-project, which I believe is the generally recommended approach.

I am a little confused though about expanding that to instead collect these reports across all of the sub-projects, especially in regards to task inputs. I think partially this comes down to 2 related things of which I am unsure -

  1. I’ve never fully grokked the difference between FileCollection and FileTree. If I understand correctly, FileCollection is essentially a collection of the directories while FileTree would represent the hierarchical contents of all of the collected directories. Is that accurate?
  2. Whether FileCollection and FileTree are valid for @InputFiles. I believe so, but just wanted to double-check. The input to this reporting is ultimately the class files for each sub-project. So I assume I really want FileTree here?

Assuming all that is correct, what is the recommended way to collect all of the class files into a FileTree?

  1. Do I build it from the sub-project’s SourceDirectorySet#classesDirectory / SourceDirectorySet#destinationDirectory?
  2. Do I build it from the sub-project’s SourceSetOutput (as a FileCollection)?
  3. Do I build it from the sub-project’s JavaCompile task? (iiuc tasks with outputs can be added directly to a FileTree)

Thanks a ton. That is a lot of detail :smiley:

If you try to reach into other projects like that, is considered unsafe cross-project publication.

See here for more information of how to properly share output between projects:

And you might want to have a look at the implementation of the test-report-aggregation and the jacoco-report-aggregation plugins which do exactly that. They “collect” the the rest results or JaCoCo results from all projects and create a combined report.

Thanks as always @Vampire!

Any clues where to find the source code for either of those plugins you mentioned as examples? I was unable to find them via Google.

They are built-in.
Just navigate to them using your IDE, or look at them in the Gradle repo: