Custom artifact resolution

I have a build where some jars live in a custom content management system.

I am trying to integrate it as follows:

task downloadXyzzy { 
    inputs.property('xyzzyPrefix', xyzzyPrefix)
    inputs.property('xyzzyVersion', xyzzyVersion)
    ext.localFile = file("$buildDir/xyzzy/downloaded.xyzzy")
    outputs.file localFile
    doLast { ... download stuff to local file }
}

task explodeXyzzy(type: Copy, dependsOn: downloadXyzzy) {
    from tarTree(downloadXyzzy.localFile)
    into file(xyzzyClasspath)
}

dependencies {
    compile 'foo.bar.acme:some_lib:1.01.53'
    compile fileTree(dir: xyzzyClasspath, includes: ['**/*.jar'], builtBy: ['explodeXyzzy'])
}

Unfortunately, even though the fileTree is executing explodeXyzzy specified by the builtBy attributew, somehow it does not see the extracted content.

This means that the build fails immediately after clean, but works the second time around.

Any ideas what is happening? Is there a better way to do this? Would it work better if I used a subproject instead of a task, or perhaps include the dependency twice?