Search code examples
javagradlefilesystemsrename

Gradle task to rename file


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.


Solution

  • 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"
    }