CombiningOperationRequest

@Incubating interface CombiningOperationRequest<FileTypeT : FileSystemLocation>
com.android.build.api.artifact.CombiningOperationRequest

Summary

Public methods

abstract Unit
toTransform(type: ArtifactTypeT)

Initiates a transform request to a multiple Artifact.Transformable artifact type.

Public methods

toTransform

abstract fun <ArtifactTypeT> toTransform(type: ArtifactTypeT): Unit where ArtifactTypeT : Artifact.MultipleArtifact<FileTypeT>, ArtifactTypeT : Artifact.Transformable

Initiates a transform request to a multiple Artifact.Transformable artifact type.

Parameters
type: ArtifactTypeT

The Artifact of FileTypeT identifying the artifact to transform.

The artifact type must be Artifact.MultipleArtifact and Artifact.Transformable.

The implementation of the task must combine all the inputs into a single output. Chained transforms will get a ListProperty containing the single output from the upstream transform.

If some append calls are made on the same artifact type, the first transform will always get the complete list of artifacts irrespective of the timing of the calls.

In the following example, let's take a Task to transform a list of org.gradle.api.file.RegularFile as inputs into a single output:

    abstract class MyTask: DefaultTask() {
         @get:InputFiles abstract val inputFiles: ListProperty<RegularFile>
         @get:OutputFile abstract val outputFile: RegularFileProperty

         @TaskAction fun taskAction() {
             ... read all inputFiles and write outputFile ...
         }
    }

An ArtifactType defined as follows :

    sealed class ArtifactType<T: FileSystemLocation>(val kind: ArtifactKind) {
         object MULTIPLE_FILE_ARTIFACT:
                 ArtifactType<RegularFile>(FILE), Multiple, Transformable
    }

You then register the task as follows:

    val taskProvider= projects.tasks.register(MyTask::class.java, "combineTask")
    artifacts.use(taskProvider)
     .wiredWith(
         MyTask::inputFiles,
         MyTask::outputFile)
     .toTransform(ArtifactType.MULTIPLE_FILE_ARTIFACT)