gradle
8.4

# ArtifactResolutionQuery

interface ArtifactResolutionQuery(source)

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

    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

## 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.
withArtifacts
Link copied to clipboard
inline fun ArtifactResolutionQuery.withArtifacts(componentType: KClass<out Component>, vararg artifactTypes: KClass<out Artifact>): ArtifactResolutionQuery
inline fun ArtifactResolutionQuery.withArtifacts(componentType: KClass<out Component>, artifactTypes: Collection<KClass<out Artifact>>): ArtifactResolutionQuery

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.artifacts.query.ArtifactResolutionQuery.withArtifacts.