How to retrieve the resolvedArtifact without iterating through 'each'

I know how to obtain the File object of a resolved dependency by iterating the then examining the name.

And that works fine, but there must a way to obtain the exact dependency I want (by its group: and name: ) WITHOUT looping and “iffing”.

I have struggled with this for a long time and always end up writing the looping code.

I want the full path (/home/foo/.gradle/caches/…) of the dependency

configurations.spectrumDependency.resolvedConfiguration.resolvedArtifacts.each { dep ->

logger.info ‘found dependency ------’ + dep.name

if ( dep.name == ‘my-artifact’ ) …

}

Any guidance to point me to the right API or examples would be appreciated.

Thanks

You can use the Groovy ‘find’ method:

def config = configurations.spectrumDependency.resolvedConfiguration
def artifact = config.resolvedArtifacts.find { it.name == "my-artifact" }

Standard groovy stuff. I should have known that.

I realize I need to find how to study the API to see that resolvedArtifacts object had a ‘find’ method (that accepts a Closure).

I assume the API has such info and I just need to dig in a bit more.

Thanks very much