copy tree with gradle and change structure?

前端 未结 3 1329
终归单人心
终归单人心 2021-02-05 14:51

Can gradle alter the structure of the tree while copying?

original

  • mod/a/src
  • mod/b/src

desired

3条回答
  •  天涯浪人
    2021-02-05 15:27

    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
    }
    

提交回复
热议问题