BuiltArtifacts

public interface BuiltArtifacts


Represents a Collection of BuiltArtifact produced by a org.gradle.api.Task.

Tasks in Android Gradle Plugin can produce more than one file in the output folder so any Artifact with a Artifact.kind of type com.android.build.api.artifact.ArtifactKind.DIRECTORY can actually contain several produced File. For instance, when dealing with multi-apk, there will be several manifest files or APKs produced by the Android Gradle Plugin.

Each produced file can be identified with unique metadata like the list of filters and/or version code or version name. This instance will allow producer and consumer org.gradle.api.Tasks to easily match produced files with this metadata without relying on name mangling or other custom solutions.

Simple use of this facility can look like :


abstract class MyTask @inject constructor(val objectFactory: ObjectFactory): DefaultTask() {
    @get:InputDirectory
    abstract val input: DirectoryProperty
    @get:OutputDirectory
    abstract val output: DirectoryProperty
    @get:Internal
    abstract val artifactsLoader: Property

    @TaskAction
    fun taskAction() {
         val builtArtifacts= artifactsLoader.get().load(
              objectFactory, input.get())

         TODO : TBD what will be surfaced here

         newBuiltArtifacts.save(output.get()))
    }
}

This BuiltArtifacts will abstract access to these produced files and provided some metadata associated with each file to be able to identify filters, version code or version name.

Summary

Nested types

Specialized version of Gradle's WorkParameters so we can retrieve the output file generated when transforming an instance of BuiltArtifacts into a new one.

Constants

default static final int

Current version of the metadata file.

Public methods

abstract @NonNull String

Returns the application ID for these BuiltArtifact instances.

abstract @NonNull Artifact<@NonNull ?>

Identifies the Artifact for this Collection of BuiltArtifact, all BuiltArtifact are the same type of artifact.

abstract @NonNull Collection<@NonNull BuiltArtifact>

Returns the Collection of BuiltArtifact.

abstract @NonNull String

Identifies the variant name for these BuiltArtifact

abstract void

Saves the metadata associated with this instance into a folder.

Constants

METADATA_FILE_VERSION

default static final int METADATA_FILE_VERSION = 3

Current version of the metadata file.

Public methods

getApplicationId

abstract @NonNull String getApplicationId()

Returns the application ID for these BuiltArtifact instances.

Returns
@NonNull String

the application ID.

getArtifactType

abstract @NonNull Artifact<@NonNull ?> getArtifactType()

Identifies the Artifact for this Collection of BuiltArtifact, all BuiltArtifact are the same type of artifact.

Returns
@NonNull Artifact<@NonNull ?>

the Artifact for all the BuiltArtifact instances.

getElements

abstract @NonNull Collection<@NonNull BuiltArtifactgetElements()

Returns the Collection of BuiltArtifact.

getVariantName

abstract @NonNull String getVariantName()

Identifies the variant name for these BuiltArtifact

save

abstract void save(@NonNull Directory out)

Saves the metadata associated with this instance into a folder.

Parameters
@NonNull Directory out

the Directory that can be used to save the metadata using a standard file name.