# ArtifactResolutionQuery

API Documentation: | `ArtifactResolutionQuery`

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

    apply plugin: '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}" }
            }
        }
    }

### Properties

No properties

### Methods

Method | Description
`execute()` | Actually execute the query, returning a query result. Note that `ArtifactResolutionQuery.withArtifacts(java.lang.Class, java.lang.Class[])` must be called before executing the query.
`forComponents(componentIds)` | Specifies the set of components to include in the result.
`forComponents(componentIds)` | Specifies the set of components to include in the result.
`forModule(group, name, version)` | Incubating Specifies a module component to include in the result using its GAV coordinates.
`withArtifacts(componentType, artifactTypes)` | Defines the type of component that is expected in the result, and the artifacts to retrieve for components of this type. Presently, only a single component type and set of artifacts is permitted.
`withArtifacts(componentType, artifactTypes)` | Incubating Defines the type of component that is expected in the result, and the artifacts to retrieve for components of this type. Presently, only a single component type and set of artifacts is permitted.

### Script blocks

No script blocks

### Method details

#### `ArtifactResolutionResult` `execute`()

Actually execute the query, returning a query result. Note that `ArtifactResolutionQuery.withArtifacts(java.lang.Class, java.lang.Class[])` must be called before executing the query.

#### `ArtifactResolutionQuery` `forComponents`(``Iterable`<? extends `ComponentIdentifier`>` componentIds)

Specifies the set of components to include in the result.

#### `ArtifactResolutionQuery` `forComponents`(``ComponentIdentifier`...` componentIds)

Specifies the set of components to include in the result.

#### `ArtifactResolutionQuery` `forModule`(`String` group, `String` name, `String` version)

Note: This method is incubating and may change in a future version of Gradle.

Specifies a module component to include in the result using its GAV coordinates.

#### `ArtifactResolutionQuery` `withArtifacts`(``Class`<? extends `Component`>` componentType, ``Class`<? extends `Artifact`>...` artifactTypes)

Defines the type of component that is expected in the result, and the artifacts to retrieve for components of this type. Presently, only a single component type and set of artifacts is permitted.

#### `ArtifactResolutionQuery` `withArtifacts`(``Class`<? extends `Component`>` componentType, ``Collection`<`Class`<? extends `Artifact`>>` artifactTypes)

Note: This method is incubating and may change in a future version of Gradle.

Defines the type of component that is expected in the result, and the artifacts to retrieve for components of this type. Presently, only a single component type and set of artifacts is permitted.