2017-06-20 83 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 
    } 
}