This message was deleted.
# community-support
s
This message was deleted.
r
I think I figured it out:
Copy code
from(files(task).asFileTree.filter {
            it.path.endsWith("dir1/dir2/file")
        })
This took the better part of an hour 😞
FileTree
is clearly powerful but I don't really understand how it works, particularly when derived from some other file collection, e.g. by filtering, merging, calling
asFileTree
...
a
Does this help?
To convert a file tree to a flat collection, use the
FileTree.getFiles()
property.
https://docs.gradle.org/current/userguide/working_with_files.html#sec:file_trees
r
That performs eager evaluation. So I can't use it
I need to copy a file that a task produces in a subdirectory, so evaluation of the
FileTree
has to wait until execution time
Alarmingly, I noticed that calling something like
getFiles()
on a
Buildable
with build dependencies just silently returns an empty file set, instead of throwing an exception
a
usually it’s best to try and use a TaskProvider, so you could do
Copy code
val files: Provider<Collection<File>> = 
   task.map { it.outputFiles.myCustomFlattenFilteringOperation() }
from(files)
Gradle will know that it needs to run
task
in order to compute
files
but if you can’t, you can try and do
Copy code
providers.provider { task.files... }
to make a custom provider (but then Gradle doesn’t realise there’s a task dependency) and I think with file collections you can even just pass in a lambda and it’ll be lazily evaluated
Copy code
from({ task.files... })
r
Ah, this is very useful!
I don't see
task.outputFiles
but I do see
task.outputs.files
I know there was a deprecated property like
task.outputDirectory
which I think was removed in Gradle 8
a
yeah sorry,
.outputFiles
is psuedo-code :)