Google is committed to advancing racial equity for Black communities. See how.

InAndOutFileOperationRequest

@Incubating interface InAndOutFileOperationRequest
com.android.build.api.artifact.InAndOutFileOperationRequest

Operations performed by a Task with a single RegularFile or Directory output.

Task is consuming existing version of the target ArtifactType and producing a new version.

Summary

Public methods

abstract Unit
toTransform(type: ArtifactTypeT)

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

Public methods

toTransform

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

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

Parameters
type: ArtifactTypeT

The Artifact identifying the artifact to transform. The Artifact's Artifact.kind must be Artifact.FILE.

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

As an example, let's take a Task transforming an input org.gradle.api.file.RegularFile into an output:

    abstract class MyTask: DefaultTask() {
         @get:InputFile abstract val inputFile: RegularFileProperty
         @get:OutputFile abstract val outputFile: RegularFileProperty

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

An ArtifactType defined as follows :

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

You can register a transform to the collection of org.gradle.api.file.RegularFile.

    val taskProvider= projects.tasks.register(MyTask::class.java, "transformTask")
    artifacts.use(taskProvider)
     .wiredWithFiles(
         MyTask::inputFile,
         MyTask::outputFile)
     .toTransform(ArtifactType.SINGLE_FILE_ARTIFACT)