使用gradle Copy/Sync从zip中提取时删除文件路径的一部分

tf7tbtn2  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(102)

给定一个声明为gradle依赖项的zip文件

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')似乎不工作,因为它只作用于文件名,这里的重命名涉及路径。

ttygqcqt

ttygqcqt1#

使用Gradle 4.5.1,以下是一个合理的传真,它的工作。
它在Sync任务上使用eachFile(doc)功能。下面,我们更改eachFile传递的FileCopyDetails对象上的路径。

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}")
    }
}

字符串

相关问题