Reputation: 1004
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.
Upvotes: 16
Views: 29611
Reputation: 558
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')
Upvotes: 3
Reputation: 455
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")
}
}
Upvotes: 8
Reputation: 20906
The rename method should do the trick.
task renameArtifacts (type: Copy) {
from ('project/')
include 'project-1.5.jar'
destinationDir file('project/')
rename 'project-1.5.jar', "project.jar"
}
Upvotes: 19