There’s probably an easier way, but the only way I know is to iterate through all files in the file tree, and add only normal files (no sub-directories):
copy {
fileTree('lib').each { file ->
if (file.isFile())
from file
}
}
hey @jvff, thanks. Unfortunately, the code you presented flattens the folder structure. What i’m looking to do instead is move a subdir from within a fileTree to a target.
I think you can convert it from a FileTree into a path, then add it with the desired sub-path.
copy {
from myFileTree.asPath + '/lib'
into myDest
}
If you need to obtain the directories in the first level of the file tree, you can transform it into a file and list its contents, adding all directories:
copy {
myFileTree.singleFile().listFiles().each { entry ->
if (entry.isDirectory())
from entry
}
into myDest
}
I’m not sure if the myFile.singleFile() call works. If it doesn’t, you can try file(myFileTree.asPath).
The only problem with the second solution is that it leaves a dangling empty lib folder in the destination. It is something I have traditionally solved by adding a doLast { delete '/path/to/lib' } action to the task.