files

Returns a ConfigurableFileCollection containing the given files. You can pass any of the following types to this method:

  • A CharSequence, including String or groovy.lang.GString. Interpreted relative to the project directory, as per file. A string that starts with file: is treated as a file URL.
  • A File. Interpreted relative to the project directory, as per file.
  • A java.nio.file.Path, as per file.
  • A java.net.URI or java.net.URL. The URL's path is interpreted as a file path. Only file: URLs are supported.
  • A org.gradle.api.file.Directory or org.gradle.api.file.RegularFile.
  • A java.util.Collection, Iterable, or an array that contains objects of any supported type. The elements of the collection are recursively converted to files.
  • A org.gradle.api.file.FileCollection. The contents of the collection are included in the returned collection.
  • A org.gradle.api.file.FileTree or org.gradle.api.file.DirectoryTree. The contents of the tree are included in the returned collection.
  • A Provider of any supported type. The provider's value is recursively converted to files. If the provider represents an output of a task, that task is executed if the file collection is used as an input to another task.
  • A java.util.concurrent.Callable that returns any supported type. The return value of the call() method is recursively converted to files. A null return value is treated as an empty collection.
  • A Groovy Closure or Kotlin function that returns any of the types listed here. The return value of the closure is recursively converted to files. A null return value is treated as an empty collection.
  • A Task. Converted to the task's output files. The task is executed if the file collection is used as an input to another task.
  • A org.gradle.api.tasks.TaskOutputs. Converted to the output files the related task. The task is executed if the file collection is used as an input to another task.
  • Anything else is treated as an error.

The returned file collection is lazy, so that the paths are evaluated only when the contents of the file collection are queried. The file collection is also live, so that it evaluates the above each time the contents of the collection is queried.

The returned file collection maintains the iteration order of the supplied paths.

The returned file collection maintains the details of the tasks that produce the files, so that these tasks are executed if this file collection is used as an input to some task.

This method can also be used to create an empty collection, which can later be mutated to add elements.

Return

The file collection. Never returns null.

Parameters

paths

The paths to the files. May be empty.


abstract fun files(paths: Any, @DelegatesTo(value = ConfigurableFileCollection::class) configureClosure: Closure): ConfigurableFileCollection(source)

Creates a new ConfigurableFileCollection using the given paths. The paths are evaluated as per files. The file collection is configured using the given closure. The file collection is passed to the closure as its delegate. Example:

files "$buildDir/classes" {
    builtBy 'compile'
}

The returned file collection is lazy, so that the paths are evaluated only when the contents of the file collection are queried. The file collection is also live, so that it evaluates the above each time the contents of the collection is queried.

Return

the configured file tree. Never returns null.

Parameters

paths

The contents of the file collection. Evaluated as per files.

configureClosure

The closure to use to configure the file collection.


abstract fun files(paths: Any, configureAction: Action<in ConfigurableFileCollection>): ConfigurableFileCollection(source)

Creates a new ConfigurableFileCollection using the given paths. The paths are evaluated as per files. The file collection is configured using the given action. Example:

files "$buildDir/classes" {
    builtBy 'compile'
}

The returned file collection is lazy, so that the paths are evaluated only when the contents of the file collection are queried. The file collection is also live, so that it evaluates the above each time the contents of the collection is queried.

Return

the configured file tree. Never returns null.

Since

3.5

Parameters

paths

The contents of the file collection. Evaluated as per files.

configureAction

The action to use to configure the file collection.