# OutOperationRequest

[View Source](https://cs.android.com/search?q=file:com/android/build/api/artifact/OperationRequests.kt+class:com.android.build.api.artifact.OutOperationRequest) Added in 4.2.0


```
interface OutOperationRequest<FileTypeT : FileSystemLocation>
```

<br />

*** ** * ** ***

Operations performed by a `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` with a single `https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFile.html` or `https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html` output.

`https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` is not consuming existing version of the target `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/SingleArtifact`.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `<ArtifactTypeT : https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Multiple<FileTypeT> & https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Appendable> https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toAppendTo(com.android.build.api.artifact.Artifact.Multiple)( type: ArtifactTypeT )` Initiates an append request to a `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Multiple` artifact type. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `@https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html <ArtifactTypeT : https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Multiple<FileTypeT> & https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Appendable & https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.WithQualifiers> https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toAppendTo(com.android.build.api.artifact.Artifact.Multiple,kotlin.collections.Map)( type: ArtifactTypeT, qualifiers: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html> )` Initiates an append request to a `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Multiple` artifact type that is also a `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.WithQualifiers`. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `<ArtifactTypeT : https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Single<FileTypeT> & https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Replaceable> https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toCreate(com.android.build.api.artifact.Artifact.Single)( type: ArtifactTypeT )` Initiates a creation request for a single `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Replaceable` artifact type. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `<ArtifactTypeT : https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Single<FileTypeT>> https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toListenTo(com.android.build.api.artifact.Artifact.Single)( type: ArtifactTypeT )` Initiates a reactive request where the `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` used in the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifacts#use(org.gradle.api.tasks.TaskProvider)` method will be executed once the final version of the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toListenTo(com.android.build.api.artifact.Artifact.Single)` artifact has been produced. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest<FileTypeT>` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#withName(kotlin.String)(name: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Sets the output file or directory name for the new artifact. |

## Public functions

### toAppendTo

Added in 7.0.0

```
fun <ArtifactTypeT : Artifact.Multiple<FileTypeT> & Artifact.Appendable> toAppendTo(
    type: ArtifactTypeT
): Unit
```

Initiates an append request to a `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Multiple` artifact type.

| Parameters |
|---|---|
| `type: ArtifactTypeT` | The `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact` of `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest` identifying the artifact to append to. The artifact type must be `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Multiple` and `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Appendable`. As an example, let's take a `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` that outputs a `https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFile.html`: ``` abstract class MyTask: DefaultTask() { @get:OutputFile abstract val outputFile: RegularFileProperty @TaskAction fun taskAction() { ... outputFile.get().asFile.write( ... ) ... } } ``` and an ArtifactType defined as follows: ``` sealed class ArtifactType<T: FileSystemLocation>(val kind: ArtifactKind) { object MULTIPLE_FILE_ARTIFACT: ArtifactType<RegularFile>(FILE), Multiple, Appendable } ``` You can then register the above task as a Provider of `https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFile.html` for that artifact type: ``` val taskProvider= projects.tasks.register(MyTask::class.java, "appendTask") artifacts.use(taskProvider) .wiredWith(MyTask::outputFile) .toAppendTo(ArtifactType.MULTIPLE_FILE_ARTIFACT) ``` |

### toAppendTo

Added in 9.6.0-alpha03

```
@Incubating
fun <ArtifactTypeT : Artifact.Multiple<FileTypeT> & Artifact.Appendable & Artifact.WithQualifiers> toAppendTo(
    type: ArtifactTypeT,
    qualifiers: Map<String, String>
): Unit
```

Initiates an append request to a `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Multiple` artifact type that is also a `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.WithQualifiers`.

| Parameters |
|---|---|
| `type: ArtifactTypeT` | The `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact` of `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest` identifying the artifact to append to. |
| `qualifiers: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>` | the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact` attributes as a Map that uniquely identifies the instance in the set of artifacts for this `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toAppendTo(com.android.build.api.artifact.Artifact.Multiple,kotlin.collections.Map)`. The artifact type must be `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Multiple`, `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Appendable` and `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.WithQualifiers` As an example, let's take a `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` that outputs a `https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFile.html`: ``` abstract class MyTask: DefaultTask() { @get:OutputFile abstract val outputFile: RegularFileProperty @TaskAction fun taskAction() { ... outputFile.get().asFile.write( ... ) ... } } ``` and an ArtifactType defined as follows : ``` sealed class ArtifactType<T: FileSystemLocation>( val kind: ArtifactKind val qualifiers: List<String> ): MultipleArtifactType { object MULTIPLE_FILE_ARTIFACT: ArtifactType<RegularFile>( FILE, listOf("ATTR_KEY_ONE", ATTR_KEY_TWO"), ), Appendable, WithQualifiers } ``` You can then register the above task as a Provider of `https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFile.html` for that artifact type: ``` val taskProvider= projects.tasks.register(MyTask::class.java, "appendTask") artifacts.use(taskProvider) .wiredWith(MyTask::outputFile) .toAppendTo(ArtifactType.MULTIPLE_FILE_ARTIFACT, mapOf("ATTR_KEY_ONE" to "valueOne, "ATTR_KEY_TWO" to "valueTwo") ``` |

### toCreate

Added in 7.0.0

```
fun <ArtifactTypeT : Artifact.Single<FileTypeT> & Artifact.Replaceable> toCreate(
    type: ArtifactTypeT
): Unit
```

Initiates a creation request for a single `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Replaceable` artifact type.

| Parameters |
|---|---|
| `type: ArtifactTypeT` | The `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact` of `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest` identifying the artifact to replace. The artifact type must be `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Replaceable` A creation request does not care about the existing producer, since it replaces the existing producer. Therefore, the existing producer task will not execute (unless it produces other outputs). Please note that when such replace requests are made, the `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` will replace initial AGP providers. You cannot replace the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Multiple` artifact type; therefore, you must instead combine it using the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/TaskBasedOperation#wiredWith(kotlin.Function1)` API. For example, let's take a `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` that outputs a `https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFile.html`: ``` abstract class MyTask: DefaultTask() { @get:OutputFile abstract val outputFile: RegularFileProperty @TaskAction fun taskAction() { ... write outputFile ... } } ``` A `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/SingleArtifact` is defined as follows: ``` sealed class ArtifactType<T: FileSystemLocation>(val kind: ArtifactKind) { object SINGLE_FILE_ARTIFACT: ArtifactType<RegularFile>(FILE), Replaceable } ``` You can register a transform to the collection of `https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFile.html`: ``` val taskProvider= projects.tasks.register(MyTask::class.java, "replaceTask") artifacts.use(taskProvider) .wiredWith(MyTask::outputFile) .toCreate(ArtifactType.SINGLE_FILE_ARTIFACT) ``` |

### toListenTo

Added in 8.3.1

```
fun <ArtifactTypeT : Artifact.Single<FileTypeT>> toListenTo(
    type: ArtifactTypeT
): Unit
```

Initiates a reactive request where the `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` used in the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifacts#use(org.gradle.api.tasks.TaskProvider)` method will be executed once the final version of the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toListenTo(com.android.build.api.artifact.Artifact.Single)` artifact has been produced.

The final version artifact will be injected in the `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html`.

Remember that an artifact is not always produced, for instance, an artifact related to minification will not be produced unless minification is turned on.

When an artifact is not produced in the current build flow, the `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` will NOT be invoked.

For example, let's take a `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` that wants to listen to the merged manifest file production :

````
    abstract class MyTask: DefaultTask() {
         @get:InputFile abstract val mergedManifestFile: RegularFileProperty

         @TaskAction fun taskAction() {
             ... verify that manifest is correct ...
         }
    }

You can register the Task that consumes the manifest file as a [org.gradle.api.file.RegularFile]:

```kotlin

val taskProvider= projects.tasks.register(MyTask::class.java, "verifyManifestTask") artifacts.use(taskProvider)
.wiredWith(MyTask::mergedManifestFile) .toListenTo(SingleArtifact.MERGED_MANIFEST)
````

`https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html` will be registered as a finalizer task for the final producer of the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toListenTo(com.android.build.api.artifact.Artifact.Single)` artifact using Gradle's `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html#finalizedBy-java.lang.Object...-` API.

| Parameters |
|---|---|
| `type: ArtifactTypeT` | the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact.Single` artifact identifier. |

### withName

Added in 8.4.0

```
fun withName(name: String): OutOperationRequest<FileTypeT>
```

Sets the output file or directory name for the new artifact.

This name will only be used when `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toAppendTo(com.android.build.api.artifact.Artifact.Multiple)` or `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toCreate(com.android.build.api.artifact.Artifact.Single)` is invoked. Although you can use this method on `https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html`, it will most likely not influence how the files contained in the resulting `https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html` are packaged in the APK or Bundle. This method is usually only useful for `https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFile.html`

Some `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact` have a `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact#name()` which cannot be changed. When invoking `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toAppendTo(com.android.build.api.artifact.Artifact.Multiple)` or `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest#toCreate(com.android.build.api.artifact.Artifact.Single)` after this method will throw an exception if trying to set such a file or directory name when the target's `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifact#name()` is not null.

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | file or directory name |

| Returns |
|---|---|
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/OutOperationRequest<FileTypeT>` | itself |