Circular dependency if rename used to create Zip containing Jar

This may be a bug, but I’ll ask here first:

apply plugin: 'java'

task dist(type:Zip) {
    from jar.outputs.files {
    //	rename { String fname -> "Something.jar" }
    }
}

build.dependsOn dist

The above build.gradle file works fine, but if I uncomment the rename it claims:

* What went wrong:
Circular dependency between the following tasks:
:dist
\--- :dist (*)

(*) - details omitted (listed previously)

That doesn’t make sense to me.

It’s not doing what you think. I’ll rewrite it as it’s being interpreted:

apply plugin: 'java'

task dist(type:Zip) {
    from(jar.outputs.files ({
        rename { String fname -> "Something.jar" }
    }))
}

build.dependsOn dist

So your Closure is adding dist as a output to jar (because rename returns a Buildable thing built by dist) and then from is adding all jar outputs as inputs to dist (because jar.outputs.files returns a Buildable thing built by jar).

You can either use parentheses to be explicit, or better:

apply plugin: 'java'

task dist(type:Zip) {
    from (jar) {
        rename { String fname -> "Something.jar" }
    }
}

build.dependsOn dist

Thank you! It’s clear now that you point it out.
The sad thing is that I have parentheses around all my other 'from’s and I removed them from only this one case! I was experimenting with the syntax vs. readability and had convinced myself they weren’t needed. On a better day I like to think I would have clued in :slight_smile: Oops.

To be extra weird, I think you could also do:

apply plugin: 'java'

task dist(type:Zip) {
    from jar, {
        rename { String fname -> "Something.jar" }
    }
}

build.dependsOn dist

But please don’t :smile: