Download dependency as part of custom task

Is it possible to manually trigger a manual download of an artifact (using the group:name:version notation) as part of a custom task?

I’d like to download a maven repo zip file and unpack as part of a pre integration test.

To add to the complexity, the version number of the artifact needs to be discovered based upon a transitive dependency of the project itself:

    • org.elasticsearch:elasticsearch:5.6.9

I want to download, but the version number (5.6.9) is defined within the spring-data-elasticsearch top level dependency (and i’d rather not hardcode the version)

I’ve made a simple method to discover the version using configurations.compile.resolvedConfiguration.resolvedArtifacts.find { ... }:

def getEsVersion() {
    return configurations.compile.resolvedConfiguration.resolvedArtifacts.find {
        return == 'org.elasticsearch' 
            && == 'elasticsearch'

I assume i need to interact with the repositories set, or the external resource resolver (hopefully pulling from the local repo after the first time its downloaded) - any ideas?

For some more context - i’d like to download the elasticsearch distribution zip as part of my integration tests setup, ensure its unzipped and start up a node for testing (yes, subjectively docker would be another / better solution).

Here’s what i’ve cobbled together that seems to work:

configurations {

dependencies {
    integTestZip "${getEsVersion()}@zip"

def getEsVersion() {

task copyESZipFromDeps(type: Copy) {
    from configurations.integTestZip.singleFile
    into "${project.rootDir}/gradle/tools"