Access Artifact(s) given a ResolvedDependencyResult

Given a org.gradle.api.artifacts.result.ResolvedDependencyResult, is there a way to access the artifact(s) represented by this dependency result?

You can use the selected component id in an artifact resolution query.

So something like the following?

ResolvedComponentResult result = ...;
        .forComponents( )

I don’t really understand what to do with the withArtifacts method

This API would allow you to get additional artifacts like the JavaDoc or Sources jars, or metadata like ivy.xml or pom.xml files. Simply, you ask for a superclass of Artifact.

That said, if you want the default artifact, (the JAR/WAR/etc itself) then you could do something like.

configurations.compile.resolvedConfiguration.resolvedArtifacts.each {
    if ( == resolvedDependencyResult.moduleVersion) {
        println it.file

Can I make a suggestion moving forward? IMO a method to bridge from a ResolvedComponentResult to its ResolveArtifact just makes too much sense… ResolvedComponentResult#getResolvedArtifact() or even ResolvedComponentResult#getResolvedArtifacts() if there can be more than one.

A follow-up question…

configurations.compile.resolvedConfiguration.resolvedArtifacts does not seem to properly account for project() deps. Am I missing something?


I found the “problem”. project.configurations.runtime.incoming.resolutionResult contains the project itself, whereas project.configurations.runtime.resolvedConfiguration.resolvedArtifacts does not.