ArtifactResolutionQuery (Gradle API 8.13)
Description: declaration: package: org.gradle.api.artifacts.query, interface: ArtifactResolutionQuery

Package org.gradle.api.artifacts.query

# Interface ArtifactResolutionQuery

public interface ArtifactResolutionQuery
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 `ArtifactView.ViewConfiguration.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}" }
             }
         }
     }

Since:
  2.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ArtifactResolutionResult`
  `execute()`
  Actually execute the query, returning a query result.
  `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)`
  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.
  `ArtifactResolutionQuery`
  `withArtifacts(Class<? extends Component> componentType, Collection<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.

- ## Method Details

  - ### forComponents

    ArtifactResolutionQuery forComponents(Iterable<? extends ComponentIdentifier> componentIds)
    Specifies the set of components to include in the result.
    Parameters:
      `componentIds` - The identifiers of the components to be queried.

  - ### forComponents

    ArtifactResolutionQuery forComponents(ComponentIdentifier... componentIds)
    Specifies the set of components to include in the result.
    Parameters:
      `componentIds` - The identifiers of the components to be queried.

  - ### forModule

    ArtifactResolutionQuery forModule(String group, String name, String version)
    Specifies a module component to include in the result using its GAV coordinates.
    Parameters:
      `group` - Module group.
      `name` - Module name.
      `version` - Module version.
    Since:
      4.5

  - ### withArtifacts

    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.
    Parameters:
      `componentType` - The expected type of the component.
      `artifactTypes` - The artifacts to retrieve for the queried components.

  - ### withArtifacts

    ArtifactResolutionQuery withArtifacts(Class<? extends Component> componentType, Collection<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.
    Parameters:
      `componentType` - The expected type of the component.
      `artifactTypes` - The artifacts to retrieve for the queried components.
    Since:
      4.5

  - ### execute

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