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 -
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?
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?
Do I build it from the sub-project’s SourceDirectorySet#classesDirectory / SourceDirectorySet#destinationDirectory?
Do I build it from the sub-project’s SourceSetOutput (as a FileCollection)?
Do I build it from the sub-project’s JavaCompile task? (iiuc tasks with outputs can be added directly to a FileTree)
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.