Include subdirectories and exclude their content with fileTree

d:\build
├── file1.txt
├── folder1
|  └── anotherfile.txt
├── folder2
|  └── subsubfolder
└── folderN

When I do

println fileTree("d:\build").collect()

I get

[d:\build\file1.txt, d:\build\folder1\anotherfile.txt]

What I want is

[d:\build\file1.txt, d:\build\folder1, d:\build\folder2, d:\build\folderN]

The reason I want to use fileTree with .collect() is because it’s lazy[0] and does not give null pointer exception[1] at configuration stage.

How do I do that?

[0] https://docs.gradle.org/current/userguide/lazy_configuration.html#working_with_files_in_lazy_properties
[1] Pass a directory which is not created yet in configuration step