这可能比我做的容易得多。我有一个字符串列表,其中列出了当前项目中动态生成的文件及其相对位置,我们希望将其添加到zip文件中。我目前有以下代码:
task sourceDrop(type: Zip) {
def filelist = getFileList()
baseName = "sourceDrop"
version = "1.0"
filelist.each {
from it // adds every single file to the archive
}
destinationDir = new File(rootProject.projectDir, "")
}
它创建了一个zip文件,其中的每个项目都是一个平面结构,没有文件夹。有没有一种优雅的方式来说";保持相对路径";?
这里的工作示例。
考虑这个任务:
task sourceDrop(type: Zip) {
def filelist = getFileList()
baseName = "sourceDrop"
version = "1.0"
fileList.each { file ->
def info = getFileInfo(file)
from (info.relativeDir) {
include info.filename into info.relativeDir
}
}
destinationDir = new File(rootProject.projectDir, "")
}
请注意,getFileInfo()
是一种自行开发的方法,它将相对路径拆分为路径和文件名。
您需要在zip(伪代码(中添加to路径
filelist.each {
from it // adds every single file to the archive
into it.substring(it.lastIndexOf("/"))
}