Copy Task Fails Silently

Hello :slight_smile:

The following task will succeed even if one of the “include files” is not found or cannot be copied to the specified destination directory. I need to make sure that that this task fails if at least one of the include files cannot be copied. What is the best way to accomplish this?

task myCopy(type: Copy) {
  outputs.upToDateWhen { false }
  from("app/build") {
    include "main.cpp"
    include "config.sh"
  }
  into "deployDir"
}

Builds are no different than other software, so consider single responsibility principle here. Ideal tasks should do one discrete piece of work. Copying a folder vs. verifying the presence of two files are different concerns, so don’t force them together.

You could technically verify them in either the source or destination, but if you pick the source, you have the opportunity to fail faster. If you already have verified that the source file exists, an exception on file copy will still cause the Copy task to fail. If you pick the destination, and the Copy task succeeds, you’ve done all the copy work, but it should be throw-away work based on the reasons you could end up there.