filegroovygradletaskfiletree

How to initialize FileTree field in Gradle custom task?


I want to create an object which implements interface FileTree in Gradle.

From what I can find from documentation FileTreeAdapter class implements FileTree, but it is internal class. How can I initialize my object filesToDelete? And how can I find which classes implements FileTree interface from the documentation?

public class DeleteDirTask extends DefaultTask {
    @InputFiles @Optional
    FileTree filesToDelete = files("/src/")
    ...
  }

Solution

  • How can I initialize my object filesToDelete?

    Use project.fileTree(). (project.files() is for FileCollections.)

    And how can I find which classes implements FileTree interface from the documentation?

    The implementation classes are internal, and you shouldn't have to worry about them.