There are really two reasons why this isn’t failing. First, you are creating two separate copy actions, so technically, within each one, there are no duplicates. The second copy action simply overwrites the file. So to get the behavior you expect, you’d have to consolidate that into a single ‘copy {…}’ block. Second, even if that were the case, the example you have would still execute because you’d simply be adding the same file twice to the ‘CopySpec’. This wouldn’t be seen as “duplicate” files. An example of this failing would be if two separate source files with the same name were copied into the same target directory. Like so:
Thanks a lot for the explanation, that wasn’t clear to me from the docs. I also think there should be a way to configure a CopySpec to not overwrite existing files. I thought that ‘duplicatesStrategy’ did that.
If there are multiple files that are going to the same destination then yes, you can prevent that by configuring the duplicatesStrategy. However, if the same file happens to exist in the output directory then Gradle will overwrite it to ensure the output reflects the latest changes.