Gradle >= 1.8: copy task fails when source file contains colon

Create a directory with a “from” directory containing an empty file called “a:b”. Then, with this build.gradle:

task c(type: Copy) {

run ‘gradle c’ and observe the following output:


 FAILURE: Build failed with an exception.

 * What went wrong:  Execution failed for task ':c'.  > Cannot convert URL 'a:b' to a file.  

This appears to have started at gradle 1.8. I ran into this with gradle 1.11 and tried every old version until I found one where it worked.

(I wish there were a preview button when editing posts.)

My workaround is to use this function:

def renameFiles(dir, pat, repl) {
  fileTree(dir).each { file ->
    def newfile = file.path.replaceAll(pat, repl)
    if (newfile != file.path) {

to replace : with @@ before copying and replace @@ back with : after copying. My real code isn’t doing just a straight copy. It is using an eachFile closure over the contents of the files.

Confirmed with 1.11 and raised GRADLE-3037. Thanks for reporting.