本文介绍了复制树与gradle和更改结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
mod / a / src mod / b / src $ b 谢谢
原始
可以在复制时改变树的结构吗? ul>- dest / mod-a / source
- > dest / mod-b / source
- dest / mod-c / source
I 'm不确定我应该在哪里创建一个闭包并覆盖复制树逻辑
我想要做与ant的globmapper功能等价的gradle。
< property name =from.dirlocation =../> < property name =to.dirlocation =dbutil/> < copy> < fileset dir =$ {from.dir}... />彼得
解决方案更改文件名时,重命名似乎是一种好方法。更改路径时,您可以覆盖 eachFile 并修改目标路径。
这很好。
copy { from($ {sourceDir}){ include'modules / ** / **'} 转换为(destDir) eachFile {details - > //顶级模块 def targetPath = rawPathToModulesPath(details.path) details.path = targetPath } } 。 ... def rawPathToModulesPath(def path){ //标准大小写模块/名称/ src - > module-name / src def modified = path.replaceAll('modules /([^/]+)/.* src /(java /)?(.*)',{module - $ {it [ 1]} / src / $ {it [3]}}) return modified }
Can gradle alter the structure of the tree while copying?
original
- mod/a/src
- mod/b/src
desired
- dest/mod-a/source
- dest/mod-b/source
- dest/mod-c/source
I'm not sure where I should create a closure and override the copy tree logic
I'd like to do the gradle equivalent of ant's globmapper functionality
<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>Thanks
Peter
解决方案When changing file name, rename seems a good approach. When changing path you can override eachFile and modify the destination path.
This works pretty well.
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和更改结构?
发布评论