2017-06-20 342 views
0

等级:如何定制processResources更改jar中的资源文件路径?gradle processResources:文件路径转换

例如:

foo/a.xml --> foo/bar/a.xml 

类似于:

copy tree with gradle and change structure?

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 
} 

如何processResources添加此?谢谢。

回答

0

processResources是类型为Copy的任务。所以你应该可以做

processResources { 
    eachFile {details -> 
     // Top Level Modules 
     def targetPath = rawPathToModulesPath(details.path) 
     details.path = targetPath 
    } 
}