SourceSet

API Documentation:SourceSet

A SourceSet represents a logical group of Java source and resource files. They are covered in more detail in the user manual.

The following example shows how you can configure the 'main' source set, which in this case involves excluding classes whose package begins 'some.unwanted.package' from compilation of the source files in the 'java' SourceDirectorySet:

plugins {
    id 'java'
}

sourceSets {
  main {
    java {
      exclude 'some/unwanted/package/**'
    }
  }
}

Properties

PropertyDescription
allJava

All Java source files for this source set. This includes, for example, source which is directly compiled, and source which is indirectly compiled through joint compilation.

allSource

All source files for this source set.

compileClasspath

The classpath used to compile this source.

extensions

The container of extensions.

java

The Java source which is to be compiled by the Java compiler into the class output directory.

name

The name of this source set.

output

SourceSetOutput is a FileCollection of all output directories (compiled classes, processed resources, etc.) and it provides means to configure the default output dirs and register additional output dirs. See examples in SourceSetOutput

resources

The non-Java resources which are to be copied into the resources output directory.

runtimeClasspath

The classpath used to execute this source.

Properties added by the antlr plugin

PropertyDescription
antlr

The AntlrSourceDirectorySet added by the antlr plugin.

Properties added by the groovy plugin

PropertyDescription
groovy

The GroovySourceDirectorySet added by the groovy plugin.

Properties added by the scala plugin

PropertyDescription
scala

The ScalaSourceDirectorySet added by the scala plugin.

Methods

MethodDescription
compiledBy(taskPaths)

Registers a set of tasks which are responsible for compiling this source set into the classes directory. The paths are evaluated as per Task.dependsOn(java.lang.Object[]).

getCompileTaskName(language)

Returns the name of a compile task for this source set.

getTaskName(verb, target)

Returns the name of a task for this source set.

java(configureAction)

Configures the Java source for this set.

resources(configureAction)

Configures the non-Java resources for this set.

Script blocks

BlockDescription
java

Configures the Java source for this set.

resources

Configures the non-Java resources for this set.

Script blocks added by the antlr plugin

BlockDescription
antlr

Configures the AntlrSourceDirectorySet added by the antlr plugin.

Script blocks added by the groovy plugin

BlockDescription
groovy

Configures the GroovySourceDirectorySet added by the groovy plugin.

Script blocks added by the scala plugin

BlockDescription
scala

Configures the ScalaSourceDirectorySet added by the scala plugin.

Property details

SourceDirectorySet allJava (read-only)

All Java source files for this source set. This includes, for example, source which is directly compiled, and source which is indirectly compiled through joint compilation.

Default with java plugin:
[java]

SourceDirectorySet allSource (read-only)

All source files for this source set.

Default with java plugin:
[java, resources]

FileCollection compileClasspath

The classpath used to compile this source.

Default with java plugin:
project.configurations.compileClasspath (or project.configurations.testCompileClasspath for the test source set).

ExtensionContainer extensions (read-only)

The container of extensions.

SourceDirectorySet java (read-only)

The Java source which is to be compiled by the Java compiler into the class output directory.

Default with java plugin:
[${project.projectDir}/src/${sourceSet.name}/java]

String name (read-only)

The name of this source set.

SourceSetOutput output (read-only)

SourceSetOutput is a FileCollection of all output directories (compiled classes, processed resources, etc.) and it provides means to configure the default output dirs and register additional output dirs. See examples in SourceSetOutput

Default with java plugin:
See SourceSetOutput

SourceDirectorySet resources (read-only)

The non-Java resources which are to be copied into the resources output directory.

Default with java plugin:
[${project.projectDir}/src/${sourceSet.name}/resources]

FileCollection runtimeClasspath

The classpath used to execute this source.

Default with java plugin:
sourceSet.output + project.configurations.runtimeClasspath (or sourceSet.output + project.configurations.testRuntimeClasspath for the test source set).

AntlrSourceDirectorySet antlr (read-only)

The AntlrSourceDirectorySet added by the antlr plugin.

GroovySourceDirectorySet groovy (read-only)

The GroovySourceDirectorySet added by the groovy plugin.

ScalaSourceDirectorySet scala (read-only)

The ScalaSourceDirectorySet added by the scala plugin.

Method details

SourceSet compiledBy(Object... taskPaths)

Registers a set of tasks which are responsible for compiling this source set into the classes directory. The paths are evaluated as per Task.dependsOn(java.lang.Object[]).

String getCompileTaskName(String language)

Returns the name of a compile task for this source set.

String getTaskName(String verb, String target)

Returns the name of a task for this source set.

SourceSet java(Action<? super SourceDirectorySet> configureAction)

Configures the Java source for this set.

The given action is used to configure the SourceDirectorySet which contains the Java source.

SourceSet resources(Action<? super SourceDirectorySet> configureAction)

Configures the non-Java resources for this set.

The given action is used to configure the SourceDirectorySet which contains the resources.

Script block details

java { }

Configures the Java source for this set.

The given closure is used to configure the SourceDirectorySet which contains the Java source.

Delegates to:
SourceDirectorySet from java

resources { }

Configures the non-Java resources for this set.

The given closure is used to configure the SourceDirectorySet which contains the resources.

Delegates to:
SourceDirectorySet from resources

antlr { }

Configures the AntlrSourceDirectorySet added by the antlr plugin.

Delegates to:
AntlrSourceDirectorySet from antlr

groovy { }

Configures the GroovySourceDirectorySet added by the groovy plugin.

scala { }

Configures the ScalaSourceDirectorySet added by the scala plugin.

Delegates to:
ScalaSourceDirectorySet from scala