gradle processResources:文件路径转换

时间:2017-06-20 04:34:57

标签: gradle process path resources

成绩:如何自定义processResources来更改jar中的资源文件路径?

例如:

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中添加它?感谢。

1 个答案:

答案 0 :(得分:0)

processResourcesCopy类型的任务。因此你应该能够做到

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