TechieHints SOFTWARE

How to copy environment specific files effectively in gradle ?

Copy task into build.gradle:

The task: myCopy searches src/main/resources and replace all the files under it with the value passed for the execution: here it is prod. -Penvironment=prod

task myCopy

  doLast 
     copy 
       from ('src/main/resources') 
                 include "*-$environment
       
     into ('src/main/resources')
     rename   
              String fileName ->
                                          fileName.replace( '-' + environment, '')
      
     
  print("Executed..")
 

Run:

gradle myCopy -Penvironment=prod

Leave a comment