This issue allow me to finally extract a zip with renaming of the root folder (e.g. ‘apache-tomcat-7.0.39.zip/apache-tomcat-7.0.39’ => ‘apache-tomcat’) without having an empty structure with old name
project.copy {
from project.zipTree(project.file('apache-tomcat-7.0.39.zip'))
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)
}
}