gradle - 用gradle复制树并改变结构?

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
}

https://stackoverflow.com/questions/13296986/

相关文章:

android - Gradle DSL 方法未找到 : "classpath()"

deployment - 从不同的文件夹运行 ant exec 任务

visual-studio-2010 - VS2010 : Exclude a project fr

build - 了解 CMake 背后的目的

c++ - 在 Eclipse 中设置构建输出目录 - c++

build - Gradle 的术语评估和执行之间的区别

gradle - 谷歌构建Android的Gradle插件源代码

android - 我已将 Android SDK 更新为 rev。昨天 22 日,工具中没有 ap

android - 如何引用公共(public)目录(不是库)中的外部 jar 文件来使用 ant

android - 我可以在不运行 Android Studio 时删除这些构建文件夹吗?