I want to do a simple file rename in a gradle task. I have a jar called project-1.5.jar under the folder src and I want the jar to be renamed to just project.jar
So,
project/project-1.5.jar to project/project.jar using gradle
Any ideas are much appreciated.
With the Gradle copy task we can define renaming rules for the files that are copied. We use the rename() method of the copy task to define the naming rules. We can use a closure where the filename is the argument of the closure. The name we return from the closure is the new name of copied file.
A FileTree represents a hierarchy of files. It extends FileCollection to add hierarchy query and manipulation methods. You typically use a FileTree to represent files to copy or the contents of an archive. You can obtain a FileTree instance using Project.
Class ProcessResourcesCopies resources from their source to their target directory, potentially processing them. Makes sure no stale resources remain in the target directory.
For me this worked - does not leave source files (no duplications).
task pdfDistributions(type: Sync) {
from('build/asciidoc/pdf/docs/asciidoc/')
into('build/asciidoc/pdf/docs/asciidoc/')
include '*.pdf'
rename { String filename ->
filename.replace(".pdf", "-${project.version}.pdf")
}
}
Gradle allows to call ant tasks from your task implementation. It makes moving files as easy as
ant.move(file:'oldFile.txt', tofile:'newfile.txt')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With