How do I copy the ivy.xml to a local folder?

Since I am having such a hard time post-processing my dependencies in the right order (many different programming languages), I decided it would be easier to get the ivy.xml and rebuild the tree myself to later walk through it, and deal with the dependency processing myself. I can copy Ivy dependencies to a local folder, but when I try to copy the ivy.xml, I get an NPE.

At the publisher, I have:

publications {
    ivy(IvyPublication) {
        artifact('src/level1-bit1.8.bit') {
             type "bit1.8"
             extension "bit"
             name "level1"

        // Remove configurations so gradle does not complain
        descriptor.withXml {
            asNode().dependencies.dependency.findAll {it.@conf}.each {it.attributes.remove("conf")}

On the consumer side, I have:

configurations {

dependencies {
    compile(group: "org.${user}", name: "module1", version: "1.0.0") {
        // Since we want non-jar dependencies, we must be explicit
        // with the DependencyHandler
        artifact {
            name = "level1"
            extension = "bit"
            type = "bit1.8"

    structure(group: "org.${user}", name: "module1", version: "1.0.0") {
        artifact {
            name = "ivy"
            extension = "xml"

            // When the type is set, the artifact is wrong: ivy-1.0.0-xml.xml
            // When the type is not set, Gradle throws an NPE
            //type = "xml"


// Copy the dependencies to some local folder
task copyDeps(type: Copy) {
    inputs.files configurations.compile
    inputs.files configurations.structure
    into "${buildDir}/layout"
    from configurations.compile
    from configurations.structure

Publshing works as expected, but the copyDeps throws an NPE. The stacktrace is rather long, so I posted it as a gist.

If I try to set the type, then Gradle attempts to get an incorrect ivy-1.0.0.xml:

Could not find ivy.xml (org.mdanjou:module1:1.0.0).
Searched in the following locations:

It adds -xml to the tail of the name. Does anyone know how to copy the ivy.xml to a local folder?

You’ll want to use an ArtifactResolutionQuery to grab the IvyDescriptorArtifact (aka the ivy.xml file).