Before you stop reading and reply “you can unzip with the Copy task” please read on
Let’s consider the following buildscript
configurations {
unzipme
}
dependencies {
unzipme 'foo:bar:1.0'
}
task unzip1(type:Copy) {
configurations.unzipme.each {
from fileTree(it)
}
into "$buildDir/unzip1"
}
task unzip2 {
inputs.files configurations.unzipme
outputs.dir "$buildDir/unzip2"
doLast {
copy {
configurations.unzipme.each {
from fileTree(it)
}
into "$buildDir/unzip2"
}
}
}
Notice how
-
unzip1
forcesconfigurations.unzipme
to be resolved at configuration time butunzip2
does not. -
The UP-TO-DATE check in
unzip2
will be more efficient since it can simply calculate a hash of the zip rather thanunzip1
which will calculate a hash of each individual file within the zip.
I think that unzip2
is a much better implementation but is quite verbose. Is there any chance the Gradle team would consider an Unzip
task? Another option is to support a transformer(s) in the copy task which would allow the zipTree(...)
operation to be delayed until execution time