给定一个zip文件声明为gradle依赖项
dependencies {
orientdb(group: "com.orientechnologies", name: "orientdb-community", version: orientdbVersion, ext: "zip")
}
其中包含以下结构的文件
.
└── orientdb-community-2.2.33
├── benchmarks
│ ├── bench_memory_get.bat
│ └── post.txt
├── bin
│ ├── backup.sh
...
可以使用以下任务将zip内容同步到给定的目标目录中,从而保留zip的完整结构:
task("deploy-db", type: Sync) {
from(configurations.orientdb.collect { zipTree(it) })
into(orientdbTgt)
}
如何配置上述任务以从结果中删除
"orientdb-community-$orientdbVersion"
目录,以便输出为:/${orientdbTgt}
├── benchmarks
│ ├── bench_memory_get.bat
│ └── post.txt
├── bin
│ ├── backup.sh
...
信息:
rename("(.*/)orientdb-community-$orientdbVersion/(.+)", '$1$2')
似乎不起作用,因为它仅作用于文件名,此处的重命名与路径有关。
最佳答案
使用Gradle 4.5.1,以下是可行的合理传真。
它在eachFile
任务上使用Sync
(doc)功能。在下面,我们更改FileCopyDetails
传递的eachFile
对象的路径。
project.ext.orientdbTgt = 'staging'
project.ext.prefixDir = "orientdb-community-2.2.33${File.separator}"
task("deploy-db", type: Sync) {
from(configurations.orientdb.collect { zipTree(it) })
into(orientdbTgt)
eachFile { fileCopyDetails ->
def originalPath = fileCopyDetails.path
fileCopyDetails.path = originalPath.replace(prefixDir, "")
}
doLast {
ant.delete(dir: "${orientdbTgt}/${prefixDir}")
}
}
关于gradle - 使用gradle复制/同步从zip提取文件时删除文件路径的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50406550/