Working with source sets
The Java plugin also adds a new concept to our project—source sets. A source set is a collection of source files that are compiled and executed together. The files can be Java source files or resource files. Source sets can be used to group together files with a certain meaning in our project, without having to create a separate project. For example, we can separate the location of source files that describe the API of our Java project in a source set, and run tasks that only apply to the files in this source set.
Without any configuration, we already have the main
and test
source sets, which are added by the Java plugin. For each source set, the plugin also adds these three tasks: compile<SourceSet>Java
, process<SourceSet>Resources
, and <SourceSet>Classes
. When the source set is named main
, we don't have to provide the source set name when we execute a task. For example, compileJava
applies to the main
source test, but compileTestJava
applies to...