How do I make a zip to contain dependency artifacts?

I think the problem is that the task is evaluated at build file read time unstead of task execution time. I wish there were a project method ‘zip’ like there is ‘copy’, and I would have been done with this hours ago. I’m not being picky-- I have no problem feeding the zip task a hand-rolled File collection, but the same problem… Gradle throws a npe even though the zip task doesn’t execute until after the Collection is populated.

task zip(dependsOn: jar, type: Zip) {
    from { configurations.runtime.allArtifacts.files }
    into( + '-' + project.version)

I was hoping that the curly braces would defer execution, but no.

My Jar task uses 7 resolved dependency files, and it echos that count as you can see below, but the zip (generated afterwards) only ever contains the primary output jar of my project… which isn’t a runtime dependency at all.

beyla$ gradlew clean jar zip

Configuration.allArtifacts.files contains only the published files from the current project. It does not include any dependencies. You should do something like this, instead:

task zip(type: Zip) {
    from configurations.runtime.allArtifacts.files
    from configurations.runtime
    into ...

Wow, awesome.

I have no idea how that magic works, but it works. Thanks so much, Adam.

Doesn’t work for me… I can never seem to get any output from any of the statements in this task:

task ss(dependsOn: [configurations.compile, configurations.runtime, configurations.archives]) << {

println “\nconfigurations.compile.allArtifacts.files = ${configurations.compile.allArtifacts.files}”

println “\nconfigurations.compile.artifacts.files = ${configurations.compile.artifacts.files.asPath}”

println “\nconfigurations.runtime.allArtifacts.files = ${configurations.runtime.allArtifacts.files}”

println “\nconfigurations.runtime.artifacts.files = ${configurations.runtime.artifacts.files.asPath}”

println “\nconfigurations.archives.allArtifacts.files = ${configurations.archives.allArtifacts.files}”

println “\nconfigurations.archives.artifacts.files = ${configurations.archives.artifacts.files.asPath}”


Ok, turns out it works in 1.0-milestone-5 (and milestone-6 snapshots) but not 1.0-milestone-3

Well that’s much better than it working in M3 and not in M5/M6!

The ‘files’ property was added to ‘allArtifacts’ in M5. I guess our dsl reference should include some information about when the property was added.

Hmm, well this is probably a fairly unique scenario as I had 3 versions of gradle installed and then was using the oldest version while looking at the documentation for a newer version.

After looking through Ivy’s documentation a lot recently and seeing how they label the versions of features throughout, I think it’s distracting. If I’m looking at the documentation for some version I shouldn’t assume some functionality is available in previous versions.

btw- I went back to using M3 after installing M5 because it’s so much faster for the kind of integrated builds I’m testing…