# ArtifactResolutionQuery

interface ArtifactResolutionQuery(source)

A builder to construct a query that can resolve selected software artifacts of the specified components.

This is a legacy API and is in maintenance mode. In future versions of Gradle, this API will be deprecated and removed. New code should not use this API. Prefer withVariantReselection for resolving sources and javadoc.

    plugins {
        id 'java'
    }

    task resolveCompileSources {
        doLast {
            def componentIds = configurations.compileClasspath.incoming.resolutionResult.allDependencies.collect { it.selected.id }

            def result = dependencies.createArtifactResolutionQuery()
                                     .forComponents(componentIds)
                                     .withArtifacts(JvmLibrary, SourcesArtifact, JavadocArtifact)
                                     .execute()

            for (component in result.resolvedComponents) {
                component.getArtifacts(SourcesArtifact).each { println "Source artifact for ${component.id}: ${it.file}" }
            }
        }
    }

Content copied to clipboard

#### Since

2.0

## Functions

execute
Link copied to clipboard
abstract fun execute(): ArtifactResolutionResult
Actually execute the query, returning a query result.
forComponents
Link copied to clipboard
abstract fun forComponents(componentIds: Iterable<out ComponentIdentifier>): ArtifactResolutionQuery
abstract fun forComponents(componentIds: Array<ComponentIdentifier>): ArtifactResolutionQuery
Specifies the set of components to include in the result.
forModule
Link copied to clipboard
abstract fun forModule(group: String, name: String, version: String): ArtifactResolutionQuery
Specifies a module component to include in the result using its GAV coordinates.
withArtifacts
Link copied to clipboard
abstract fun withArtifacts(componentType: Class<out Component>, artifactTypes: Array<Class<out Artifact>>): ArtifactResolutionQuery
abstract fun withArtifacts(componentType: Class<out Component>, artifactTypes: Collection<Class<out Artifact>>): ArtifactResolutionQuery
Defines the type of component that is expected in the result, and the artifacts to retrieve for components of this type.