Reputation: 59
I have the following gradle task that unzips a dependency which has been downloaded to tmp
.
task unzip(type: Copy) {
def zipFile = file('tmp/dist-1.0.1.zip')
def outDir = file("unpacked/dist")
from zipTree(zipFile)
into outDir
}
However, I'm looking to download the latest version of the dependency rather than a specific version (i.e. the script will download dist-1.0.+
).
Is there a way that I can unzip the dependency, no matter which version of the dependency has been downloaded?
Upvotes: 2
Views: 870
Reputation: 23657
Add a new configuration, so as not to pollute existing project configurations:
configurations{
download
}
Add a dependency into the declared configuration, with version wildcard as desired. Just using +
for version will get you the latest version available in the declared repositories:
dependencies{
download `foo:bar:+`
}
Unzip the resolved dependency:
task unzip(type: Copy) {
def zipPath = project.configurations.download.find {it.name.startsWith('bar') }
def zipFile = file(zipPath)
def outDir = file("unpacked/dist")
from zipTree(zipFile)
into outDir
}
Note: it is generally a bad practice to use wildcard in project dependency versions. This makes the build non-deterministic - if a newer version of a dependency with breaking changes is published to the source repo, it could break your build.
Upvotes: 6