Change to CopySpec#eachFile(Closure) behaviour in gradle 1.8


Given the following task:

task copyFiles(type:Copy) {
    from 'src'
into "${buildDir}"
  eachFile { println it.file

and the following file:


In Gradle 1.8 the eachFile closure gets called for each parent directory:

:copyFiles  src\conf  src\conf\  

Whereas when I run the task in Gradle 1.6, I get the following output:

:copyFiles  src\conf\  

I couldn’t see anything in the 1.7/1.8 release notes to suggest this was an intentional change.

It’s a known issue with 1.8.

Actually, it’s similar to but not quite the same as GRADLE-2900. Raised GRADLE-2906. Thanks for reporting.

This issue allow me to finally extract a zip with renaming of the root folder (e.g. ‘’ => ‘apache-tomcat’) without having an empty structure with old name

project.copy {
 from project.zipTree(project.file(''))
 into project.buildDir
 // Change root folder
 eachFile { FileCopyDetails fcp ->
  def segments = ['apache-tomcat'] + (fcp.relativePath.segments.size() == 1 ? [] : fcp.relativePath.segments[1..-1])
  def pathsegments = segments as String[]
  fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), pathsegments)