What's the most elegant way to copy just one file with gradle

Viewed 4563

What's the most concise and most elegant and the shortest way to copy just one file AND rename it with gradle?

So far I could think of just this:

copy {
    from projectDir
    into projectDir
    include '.env.template'
    rename '.env.template', '.env'
}
2 Answers
task copySingleFileInGradle {
   doFirst {
      def src = new File("sourcefile")        // this must exist in top-level project dir
      def dst = new File("destinationFile")   // this will get created when task is run
      dst.write(src.text)
   }
}
Related