Skip to content Skip to sidebar Skip to footer

Rename File In Gradle With Passed Parameter

I'm packaging up my build artefacts from a gradle build. It's an Android Studio project. I have tasks that successfully create a zip file containing two jars. Let's say the zip fil

Solution 1:

rename is a method on CopyProcessingSpec, that configures the task to perform some renamings while operating. If you wrap it in doLast, the copying has already happened, and no rename will be performed. Furthermore, rename takes only file names, not relative or absolute file paths. This should work:

project.ext.versionString = versionString
task renameArtifacts (type: Copy) {
    from ('build/')
    include 'my.zip'
    destinationDir file('build/')
    rename 'my.zip', "my-${project.versionString}.zip"
}

Edit: $versionString is not accessible in tasks. Using extra project property is the suggested way how to pass these in tasks (see here).

Post a Comment for "Rename File In Gradle With Passed Parameter"