Table of Contents
API Documentation: | SourceSetOutput |
---|
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')) } }
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!" } }
Find more information in SourceSetOutput.dir(java.lang.Object)
and SourceSetOutput.getDirs()
Property | Description |
classesDirs | The directories containing compiled classes. |
resourcesDir | The output directory for resources |
Method | Description |
dir(dir) | Registers an extra output dir. Useful for generated resources. |
dir(options, dir) | Registers an extra output dir and the builtBy information. Useful for generated resources. |
getDirs() | Returns all dirs registered with #dir method.
Each file is resolved as |
FileCollection
classesDirs
(read-only)
The directories containing compiled classes.
- Default with
java
plugin: - a file collection of each
${project.layout.buildDirectory}
/classes/${sourceDirectorySet.name}
/${sourceSet.name}
File
resourcesDir
The output directory for resources
See example at SourceSetOutput
- Default with
java
plugin: ${project.layout.buildDirectory}
/classes/${sourceSet.name}
void
dir
(Object
dir)
Registers an extra output dir. Useful for generated resources.
See example at SourceSetOutput
Registers an extra output dir and the builtBy information. Useful for generated resources.
See example at SourceSetOutput
FileCollection
getDirs
()
Returns all dirs registered with #dir method.
Each file is resolved as Project.file(java.lang.Object)
See example at SourceSetOutput