Introduction to FileTree in Gradle Api
FileTree is an interface that extends FileCollection and
introduces methods like
visit(). It class represents a hierarchy of
files in a given directory. It includes files in same folder and all sub folders.
How to get all files in a Directory
To load all files in a given directory and its sub directories you can use
FileTree. Syntax for
FileTree is as shown below.
FileTree tree = fileTree('path/to/dir')
The FileTree can get files in following ways
- from relative path
We can write a gradle task to list all the files in the src folder as shown below.
FileTree tree = fileTree('src')
When we run the aobe task using command
gradle -q loadFiles it will give the following output