interface SourceSetOutput : FileCollection
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.
apply plugin: 'java' sourceSets { main { //if you truly want to override the defaults: output.resourcesDir = file('out/bin') // Compiled Java classes should use this directory java.outputDir = file('out/bin') } }
Working with generated resources.
In general, we recommend generating resources into folders different than the regular resourcesDir and classesDir. 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:
apply plugin: 'java' def generatedResources = "$buildDir/generated-resources/main" sourceSets { main { //let's register an output folder on the main SourceSet: output.dir(generatedResources, builtBy: 'generateMyResources') //it is now a part of the 'main' classpath and will be a part of the jar } } //a task that generates the resources: task generateMyResources { doLast { def generated = new File(generatedResources, "myGeneratedResource.properties") generated.text = "message=Stay happy!" } } //Java plugin task 'classes' and 'testClasses' will automatically depend on relevant tasks registered with 'builtBy' //Eclipse/IDEA plugins will automatically depend on 'generateMyResources' //because the output dir was registered with 'builtBy' information apply plugin: 'idea'; apply plugin: 'eclipse'
Find more information in #dir(java.util.Map, Object)
and #getDirs()
abstract fun dir(options: MutableMap<String, Any>, dir: Any): Unit
Registers an extra output dir and the builtBy information. Useful for generated resources. See example at SourceSetOutput abstract fun dir(dir: Any): Unit
Registers an extra output dir. Useful for generated resources. See example at SourceSetOutput |
|
abstract fun getClassesDir(): File
Returns the directory to assemble the compiled classes into. See example at SourceSetOutput |
|
abstract fun getClassesDirs(): FileCollection
Returns the directories containing compiled classes. |
|
abstract fun getDirs(): FileCollection
Returns all dirs registered with #dir method. Each file is resolved as See example at SourceSetOutput |
|
abstract fun getResourcesDir(): File
Returns the output directory for resources See example at SourceSetOutput |
|
abstract fun isLegacyLayout(): Boolean
Source set uses the legacy layout (single classes directory for the entire source set). |
|
abstract fun setClassesDir(classesDir: File): Unit abstract fun setClassesDir(classesDir: Any): Unit
Sets the directory to assemble the compiled classes into. See example at SourceSetOutput |
|
abstract fun setResourcesDir(resourcesDir: File): Unit abstract fun setResourcesDir(resourcesDir: Any): Unit
Sets the output directory for resources See example at SourceSetOutput |
abstract fun add(collection: FileCollection): FileCollection
Adds another collection to this collection. This is an optional operation. |
|
abstract fun addToAntBuilder(builder: Any, nodeName: String, type: AntType): Unit
Adds this collection to an Ant task as a nested node. The given type determines how this collection is added:
AntType#ResourceCollection , if the target Ant task supports it, as this is generally the most efficient. Using the other types may involve copying the contents of this collection to a temporary directory.
abstract fun addToAntBuilder(builder: Any, nodeName: String): Any
Adds this collection to an Ant task as a nested node. Equivalent to calling |
|
abstract fun asType(type: Class<*>): Any
Converts this collection into an object of the specified type. Supported types are: You can call this method in your build script using the |
|
abstract fun contains(file: File): Boolean
Determines whether this collection contains the given file. Generally, this method is more efficient than calling |
|
abstract fun filter(filterClosure: Closure<Any>): FileCollection
Restricts the contents of this collection to those files which match the given criteria. The filtered collection is live, so that it reflects any changes to this collection. The given closure is passed the File as a parameter, and should return a boolean value. abstract fun filter(filterSpec: Spec<in File>): FileCollection
Restricts the contents of this collection to those files which match the given criteria. The filtered collection is live, so that it reflects any changes to this collection. |
|
abstract fun getAsFileTree(): FileTree
Converts this collection to a FileTree. Generally, for each file in this collection, the resulting file tree will contain the source file at the root of the tree. For each directory in this collection, the resulting file tree will contain all the files under the source directory. |
|
abstract fun getAsPath(): String
Returns the contents of this collection as a platform-specific path. This can be used, for example, in an Ant <path> element. |
|
abstract fun getFiles(): MutableSet<File>
Returns the contents of this collection as a Set. |
|
abstract fun getSingleFile(): File
Returns the content of this collection, asserting it contains exactly one file. |
|
abstract fun isEmpty(): Boolean
Returns true if this collection is empty. Generally, calling this method is more efficient than calling |
|
abstract fun minus(collection: FileCollection): FileCollection
Returns a You can call this method in your build script using the |
|
abstract fun plus(collection: FileCollection): FileCollection
Returns a You can call this method in your build script using the |
|
abstract fun stopExecutionIfEmpty(): FileCollection
Throws a StopExecutionException if this collection is empty. |