ArtifactResolutionQuery

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}" }
        }
    }
}

Since

2.0

Functions

Link copied to clipboard
Actually execute the query, returning a query result.
Link copied to clipboard
Specifies the set of components to include in the result.
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.
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.
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.