API 文档 | ArtifactResolutionQuery |
---|
一个用于构建查询的构建器,该查询可以解析指定组件的选定软件制品。
这是一个遗留 API,目前处于维护模式。在 Gradle 的未来版本中,此 API 将被废弃并移除。新代码不应使用此 API。建议使用<UNHANDLED-LINK>ArtifactView.ViewConfiguration#withVariantReselection()</UNHANDLED-LINK>来解析源代码和 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}" } } } }
方法 | 描述 |
execute() | 实际执行查询,返回查询结果。请注意,在执行查询之前,必须调用 |
forComponents(componentIds) | 指定要包含在结果中的组件集。 |
forComponents(componentIds) | 指定要包含在结果中的组件集。 |
forModule(group, name, version) | 使用 GAV 坐标指定要包含在结果中的模块组件。 |
withArtifacts(componentType, artifactTypes) | 定义结果中预期的组件类型,以及要为此类型组件检索的制品。目前,只允许单个组件类型和一组制品。 |
withArtifacts(componentType, artifactTypes) | 定义结果中预期的组件类型,以及要为此类型组件检索的制品。目前,只允许单个组件类型和一组制品。 |
ArtifactResolutionResult
execute
()
实际执行查询,返回查询结果。请注意,在执行查询之前,必须调用ArtifactResolutionQuery.withArtifacts(java.lang.Class, java.lang.Class[])
。
ArtifactResolutionQuery
forComponents
(Iterable
<? extends ComponentIdentifier
>
componentIds)
Iterable
<? extends ComponentIdentifier
>指定要包含在结果中的组件集。
ArtifactResolutionQuery
forComponents
(ComponentIdentifier
...
componentIds)
ComponentIdentifier
...指定要包含在结果中的组件集。
ArtifactResolutionQuery
forModule
(String
group, String
name, String
version)
使用 GAV 坐标指定要包含在结果中的模块组件。
ArtifactResolutionQuery
withArtifacts
(Class
<? extends Component
>
componentType, Class
<? extends Artifact
>...
artifactTypes)
Class
<? extends Component
>Class
<? extends Artifact
>...定义结果中预期的组件类型,以及要为此类型组件检索的制品。目前,只允许单个组件类型和一组制品。
ArtifactResolutionQuery
withArtifacts
(Class
<? extends Component
>
componentType, Collection
<Class
<? extends Artifact
>>
artifactTypes)
Class
<? extends Component
>Collection
<Class
<? extends Artifact
>>定义结果中预期的组件类型,以及要为此类型组件检索的制品。目前,只允许单个组件类型和一组制品。