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


(Jay Berkenbilt) #1

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

task c(type: Copy) {
  from('from')
  into('to')
}

run ‘gradle c’ and observe the following output:

  :c FAILED

 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.


(Jay Berkenbilt) #2

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


(Jay Berkenbilt) #3

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) {
      file.renameTo(newfile)
    }
  }
}

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.


(Peter Niederwieser) #4

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