I need to aggregate files from other subprojects i...
# community-support
a
I need to aggregate files from other subprojects into an aggregating-subproject, but I need to keep track of configurable ID from the source subprojects so that the files are grouped by the ID. I’m fetching the files via Configurations, and grouping the files by an attribute that contains the ID. (The attribute is present on outgoing Configurations, but not the consuming Configuration
moduleFooFilesConsumer
, so Gradle ignores it for matching).
Copy code
// this configuration is used in the `build.gradle.kts` - dependencies { moduleFooFiles(project(":alpha") }
val moduleFooFilesConsumer: NamedDomainObjectProvider<Configuration> = //...

val moduleFooFilesGroupedById: Provider<Map<String?, FileCollection>> =
  moduleFooFilesConsumer
    .map { conf ->
      conf
        .incoming
        .artifactView { lenient(true) }
        .artifacts
        .filter { artifact ->
          artifact.variant.attributes.getAttribute(MODULE_ID_ATTRIBUTE) != null
        }.groupingBy { artifact ->
          artifact.variant.attributes.getAttribute(MODULE_ID_ATTRIBUTE)!!.name
        }.fold(objects.fileCollection()) { files, element ->
          files.from(element.file)
        }
    }
There are actually a few similar file types - FooFiles, BarFiles, BazFiles - that need to be ‘transmitted’ separately and then the files of all type types are grouped by module ID into some class (to be used by a JavaExec operation in an isolated Gradle Worker)
Copy code
data class IncomingModule(
  val moduleId: String,
  val fooFiles: FileCollection,
  val barFile: File,
  val bazFiles: FileCollection,
)
IncomingModule
needs to be created in a task - but what’s the correct task input for a property of type
Provider<Map<String?, FileCollection>>
? I need one that will perform normalization on the files.