# SourceSetOutput

interface SourceSetOutput : FileCollection(source)

A collection of all output directories (compiled classes, processed resources, etc.) - notice that SourceSetOutput extends FileCollection.

Provides output information of the source set. Allows configuring the default output dirs and specify additional output dirs.

    plugins {
        id 'java'
    }

    sourceSets {
      main {
        //if you truly want to override the defaults:
        output.resourcesDir = file('out/bin')
        // Compiled Java classes should use this directory
        java.destinationDirectory.set(file('out/bin'))
      }
    }

Content copied to clipboard
Working with generated resources.

In general, we recommend generating resources into folders different than the regular resourcesDir and classesDirs. Usually, it makes the build easier to understand and maintain. Also it gives some additional benefits because other Gradle plugins can take advantage of the output dirs 'registered' in the SourceSet.output. For example: Java plugin will use those dirs in calculating class paths and for jarring the content; IDEA and Eclipse plugins will put those folders on relevant classpath.

An example how to work with generated resources:

    plugins {
      id 'java'
    }

    def generateResourcesTask = tasks.register("generate-resources", GenerateResourcesTask) {
      resourcesDir.set(layout.buildDirectory.dir("generated-resources/main"))
    }

    // Include all outputs of the `generate-resources` task as outputs of the main sourceSet.
    sourceSets {
      main {
        output.dir(generateResourcesTask)
      }
    }

    abstract class GenerateResourcesTask extends DefaultTask {
      @OutputDirectory
      abstract DirectoryProperty getResourcesDir()

      @TaskAction
      def generateResources() {
        def generated = resourcesDir.file("myGeneratedResource.properties").get().asFile
        generated.text = "message=Stay happy!"
      }
    }

Content copied to clipboard
Find more information in dir and getDirs

#### Since

1.0

## Functions

addToAntBuilder
Link copied to clipboard
abstract fun addToAntBuilder(builder: Any, nodeName: String): Any
abstract fun addToAntBuilder(builder: Any, nodeName: String, type: FileCollection.AntType)
Adds this collection to an Ant task as a nested node.
abstract fun addToAntBuilder(node: Any, childNodeName: String): Any
Add to ant builder.
contains
Link copied to clipboard
abstract fun contains(file: File): Boolean
Determines whether this collection contains the given file.
dir
Link copied to clipboard
abstract fun dir(dir: Any)
Registers an extra output dir.
abstract fun dir(options: Map<String, Any>, dir: Any)
Registers an extra output dir and the builtBy information.
dir
Link copied to clipboard
inline fun SourceSetOutput. dir(dir: Any, vararg options: Pair<String, Any>)

Kotlin extension function for org.gradle.api.tasks.SourceSetOutput.dir.

filter
Link copied to clipboard
abstract fun filter(filterClosure: Closure): FileCollection
abstract fun filter(filterSpec: Spec<in File>): FileCollection
Restricts the contents of this collection to those files which match the given criteria.
forEach
Link copied to clipboard
open fun forEach(action: Consumer<in T>)
getAsFileTree
Link copied to clipboard
abstract fun getAsFileTree(): FileTree
Converts this collection to a FileTree, if not already.
getAsPath
Link copied to clipboard
abstract fun getAsPath(): String
Returns the contents of this collection as a platform-specific path.
getBuildDependencies
Link copied to clipboard
abstract fun getBuildDependencies(): TaskDependency
Returns a dependency which contains the tasks which build this artifact.
getClassesDirs
Link copied to clipboard
abstract fun getClassesDirs(): FileCollection
Returns the directories containing compiled classes.
getDirs
Link copied to clipboard
abstract fun getDirs(): FileCollection
Returns all dirs registered with #dir method.
getElements
Link copied to clipboard
abstract fun getElements(): Provider<Set<FileSystemLocation>>
Returns the contents of this file collection as a Provider of FileSystemLocation instances.
getFiles
Link copied to clipboard
abstract fun getFiles(): Set<File>
Returns the contents of this collection as a Set.
getGeneratedSourcesDirs
Link copied to clipboard
abstract fun getGeneratedSourcesDirs(): FileCollection
Returns the directories containing generated source files (e.g.
getResourcesDir
Link copied to clipboard
@Nullable
abstract fun getResourcesDir(): @Nullable File
Returns the output directory for resources See example at SourceSetOutput
getSingleFile
Link copied to clipboard
abstract fun getSingleFile(): File
Returns the content of this collection, asserting it contains exactly one file.
isEmpty
Link copied to clipboard
abstract fun isEmpty(): Boolean
Returns true if this collection is empty.
iterator
Link copied to clipboard
abstract fun iterator(): Iterator<T>
minus
Link copied to clipboard
abstract fun minus(collection: FileCollection): FileCollection
Returns a `FileCollection` which contains the difference between this collection and the given collection.
plus
Link copied to clipboard
abstract fun plus(collection: FileCollection): FileCollection
Returns a `FileCollection` which contains the union of this collection and the given collection.
setResourcesDir
Link copied to clipboard
abstract fun setResourcesDir(resourcesDir: File)
abstract fun setResourcesDir(resourcesDir: Any)
Sets the output directory for resources See example at SourceSetOutput
spliterator
Link copied to clipboard
open fun spliterator(): Spliterator<T>