我有以下 gradle 任务可以解压缩已下载到tmp
.
task unzip(type: Copy) {
def zipFile = file('tmp/dist-1.0.1.zip')
def outDir = file("unpacked/dist")
from zipTree(zipFile)
into outDir
}
Run Code Online (Sandbox Code Playgroud)
但是,我希望下载最新版本的依赖项而不是特定版本(即脚本将下载dist-1.0.+
)。
无论下载了哪个版本的依赖项,有没有办法解压缩依赖项?
添加新的配置,以免污染现有的项目配置:
configurations{
download
}
Run Code Online (Sandbox Code Playgroud)
将依赖项添加到声明的配置中,并根据需要使用版本通配符。仅使用+
for version 将为您提供声明的存储库中可用的最新版本:
dependencies{
download `foo:bar:+`
}
Run Code Online (Sandbox Code Playgroud)
解压缩已解决的依赖项:
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
}
Run Code Online (Sandbox Code Playgroud)
注意:在项目依赖版本中使用通配符通常是一种不好的做法。这使得构建具有不确定性 - 如果将具有破坏性更改的更新版本的依赖项发布到源存储库,它可能会破坏您的构建。
归档时间: |
|
查看次数: |
781 次 |
最近记录: |