复制树与gradle和更改结构? [英] copy tree with gradle and change structure?

查看:153
本文介绍了复制树与gradle和更改结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原始



可以在复制时改变树的结构吗? ul>
  • mod / a / src

  • mod / b / src




  • $ b

    • 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}... />
    < / copy>

    谢谢

    彼得

    解决方案

    更改文件名时,重命名似乎是一种好方法。更改路径时,您可以覆盖 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和更改结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆