Copy task executes, but doesn't copy

Hello all,

Here I am yet again with another question about a copy task.

I would like to create a backup of a file whose path is in my file. The file has to be copied to a path which is in the same properties file, with a timestamp added at the end.

For some reason or another, the copy task works perfectly when I simply use self typed paths, but not when I start using the paths from the properties file.

The code snippet I have is as follows:

task backupFiles(type: Copy) {
    String backupDestinationDirectory = backup_file_path
    backupDestinationDirectory = "'" + backupDestinationDirectory + new Date().format('') + "/" + "'"
      from properties_file
    into backupDestinationDirectory
      rename { String fileName ->
        String extension = ""
        ... determine extension ...
        fileName -= extension
        fileName += "-" + new Date().format('') + extension
        return fileName

This is a wild guess of mine, but does this have something to do with the from and into being set at configuration phase? Or am I completely wrong?

Anyways, I hope someone is able to point me in the right direction.


~ Joe

Hello Joe, it seems that the code snippet you provided is broken. right? Where is your located. in your project or in your user home?

My first guess is, that you might used relative paths which are not resolved correctly.

Hi Rene,

First of all, I’m using absolute paths, so that shouldn’t be the problem. The file is in the same directory as build.gradle.

I think I fixed the code snippet by now, at least, it seems fixed to me!

EDIT: this is the line that gets called from my file:


~ Joe

Eventually managed to resolve it on my own. The solution was to remove the quote signs from the file path, first declaring them as a String in the task, and placing file() around the property name.

This looks as follows:

task backupFiles(type: Copy) {
    String propDestination = ... .replaceAll(<quotes>, "")
    String propFile = ... . replaceAll(<quotes>, "")
      from file(propFile)
    into file(propDestination)

The reason I put quotes between tags there is because otherwise the code snippet gets broken. What actually needs to be there, is this: “”"

~ Joe