ArtifactResolutionQuery

一个构建器,用于构造可解析指定组件的选定软件构件的查询。

这是一个遗留 API,处于维护模式。在未来版本的 Gradle 中,此 API 将被弃用并移除。新代码不应使用此 API。对于解析源码和 Javadoc,推荐使用 <UNHANDLED-LINK>ArtifactView.ViewConfiguration#withVariantReselection()</UNHANDLED-LINK>

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

属性

无属性

方法

方法描述
execute()

实际执行查询,返回查询结果。请注意,必须在执行查询之前调用 ArtifactResolutionQuery.withArtifacts(java.lang.Class, java.lang.Class[])

forComponents(componentIds)

指定要包含在结果中的组件集。

forComponents(componentIds)

指定要包含在结果中的组件集。

forModule(group, name, version)

使用 GAV 坐标指定要包含在结果中的模块组件。

withArtifacts(componentType, artifactTypes)

定义结果中预期的组件类型,以及为此类型组件检索的构件。目前,只允许指定单一组件类型和构件集。

withArtifacts(componentType, artifactTypes)

定义结果中预期的组件类型,以及为此类型组件检索的构件。目前,只允许指定单一组件类型和构件集。

脚本块

无脚本块

方法详情

实际执行查询,返回查询结果。请注意,必须在执行查询之前调用 ArtifactResolutionQuery.withArtifacts(java.lang.Class, java.lang.Class[])

ArtifactResolutionQuery forComponents(Iterable<? extends ComponentIdentifier> componentIds)

指定要包含在结果中的组件集。

ArtifactResolutionQuery forComponents(ComponentIdentifier... componentIds)

指定要包含在结果中的组件集。

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

使用 GAV 坐标指定要包含在结果中的模块组件。

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

定义结果中预期的组件类型,以及为此类型组件检索的构件。目前,只允许指定单一组件类型和构件集。

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

定义结果中预期的组件类型,以及为此类型组件检索的构件。目前,只允许指定单一组件类型和构件集。