0

Grade: how to customize processResources to change the resource file path in the jar?

For example:

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

something similar to:

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
}

How to add this in processResources? Thanks.

Rene Groeschke
  • 27,999
  • 10
  • 69
  • 78
eastwater
  • 4,624
  • 9
  • 49
  • 118

1 Answers1

0

processResources is a task of type Copy. Therefore you should be able to do

processResources {
   eachFile {details ->
       // Top Level Modules
       def targetPath = rawPathToModulesPath(details.path)
       details.path = targetPath
   }
}
Rene Groeschke
  • 27,999
  • 10
  • 69
  • 78