gradle 可以在复制时改变树的结构吗?
原创
- mod/a/src
- mod/b/src
想要的
- dest/mod-a/source
- dest/mod-b/source
- dest/mod-c/source
我不确定应该在哪里创建闭包并覆盖复制树逻辑
我想做与 ant 的 globmapper 功能等效的 gradle
<property name="from.dir" location=".."/>
<property name="to.dir" location="dbutil"/>
<copy>
<fileset dir="${from.dir}" ... />
<globmapper from="${from.dir}/*/db" to="${to.dir}"/>
</copy>
谢谢
彼得
最佳答案
更改文件名时,重命名似乎是一个不错的方法。更改路径时,您可以覆盖 eachFile 并修改目标路径。
这很好用。
copy {
from("${sourceDir}") {
include 'modules/**/**'
}
into(destDir)
eachFile {details ->
// Top Level Modules
def targetPath = rawPathToModulesPath(details.path)
details.path = targetPath
}
}
....
def rawPathToModulesPath(def path) {
// Standard case modules/name/src -> module-name/src
def modified=path.replaceAll('modules/([^/]+)/.*src/(java/)?(.*)', {"module-${it[1]}/src/${it[3]}"})
return modified
}
关于gradle - 用gradle复制树并改变结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13296986/