{"id":22912,"date":"2015-05-05T11:00:41","date_gmt":"2015-05-05T08:00:41","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=22912"},"modified":"2019-04-03T14:02:19","modified_gmt":"2019-04-03T11:02:19","slug":"gradle-sourcesets-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/","title":{"rendered":"Gradle SourceSets Example"},"content":{"rendered":"<p>Gradle SourceSets are&nbsp;a key concept for the Gradle Java Plugin which define the structure of Java Source Files. In this example will see how to use this concept, customize them through gradle properties, create a new sourceset, get documentation and assembling them in a JAR.<\/p>\n<h2>1. Introduction to Gradle SourceSets<\/h2>\n<h3>1.1 What is a Gradle SourceSet ?<\/h3>\n<p>A SourceSet is a collection of java source files and additional resource files that are compiled and assembled together to be executed. The main idea of sourcesets is to group files with a common meaning for the project, with no need of separate them in another project.\n<\/p>\n<h2>2.&nbsp;What do We Need?<\/h2>\n<ol>\n<li>As IDE: Eclipse Luna 4.4<\/li>\n<li>Eclipse Gradle Plugin<\/li>\n<li>JDK 1.7_75 or&nbsp;higher<\/li>\n<li>Gradle 2.3<\/li>\n<\/ol>\n<p>But the main idea is to edit a <code>build.gradle<\/code> script and you can do this with only a plain text editor, also should have a java project ready to work on it.<\/p>\n<h2>3.Environment Configuration<\/h2>\n<p>Please set your Gradle environment variables and install the Gradle plugin on your IDE. To avoid to be boilerplate visit this previous posts that show how to configure your Gradle Environment.&nbsp;<a href=\"http:\/\/examples.javacodegeeks.com\/core-java\/gradle\/gradle-hello-world-tutorial\/\" target=\"_blank\" rel=\"noopener noreferrer\">Gradle Hello World Tutorial<\/a>&nbsp;&amp;&nbsp;<a href=\"http:\/\/examples.javacodegeeks.com\/core-java\/gradle\/gradle-gwt-integration-example\/\" target=\"_blank\" rel=\"noopener noreferrer\">Gradle GWT Integration Example<\/a><\/p>\n<h2>4.Creating a Gradle Project<\/h2>\n<p>Go to the Eclipse Wizard and then use Gradle Project Wizard.<\/p>\n<p><figure id=\"attachment_24240\" aria-describedby=\"caption-attachment-24240\" style=\"width: 703px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sourceset_project1.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sourceset_project1.jpg\" alt=\"Gradle SourceSet Project Wizard\" width=\"703\" height=\"531\" class=\"size-full wp-image-24240\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sourceset_project1.jpg 703w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sourceset_project1-300x227.jpg 300w\" sizes=\"(max-width: 703px) 100vw, 703px\" \/><\/a><figcaption id=\"caption-attachment-24240\" class=\"wp-caption-text\">Gradle SourceSet Project Wizard<\/figcaption><\/figure><\/p>\n<p>Then, please choose in sample project Java API and Implementation because is most useful for this example, but you can use any other.<\/p>\n<p><figure id=\"attachment_24238\" aria-describedby=\"caption-attachment-24238\" style=\"width: 697px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sample_project2.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sample_project2.jpg\" alt=\"Gradle Sourceset Sample Project\" width=\"697\" height=\"522\" class=\"size-full wp-image-24238\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sample_project2.jpg 697w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sample_project2-300x225.jpg 300w\" sizes=\"(max-width: 697px) 100vw, 697px\" \/><\/a><figcaption id=\"caption-attachment-24238\" class=\"wp-caption-text\">Gradle Sourceset Sample Project<\/figcaption><\/figure><\/p>\n<h2>5.Generated Build.Gradle (New SourceSet Definition)<\/h2>\n<p>If we go to the build.gradle file in project&#8217;s root, we find a script like this:<\/p>\n<pre class=\"brush:java\">apply plugin: \"java\"\napply plugin: \"maven\"\n\ngroup = \"myorg\"\nversion = 1.0\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    apiCompile 'commons-codec:commons-codec:1.5'\n\n    implCompile sourceSets.api.output\n    implCompile 'commons-lang:commons-lang:2.6'\n\n    testCompile 'junit:junit:4.9'\n    testCompile sourceSets.api.output\n    testCompile sourceSets.impl.output\n    runtime configurations.apiRuntime\n    runtime configurations.implRuntime\n}\n\nsourceSets.all { set -&gt;\n    def jarTask = task(\"${set.name}Jar\", type: Jar) {\n        baseName = baseName + \"-$set.name\"\n        from set.output\n    }\n\n    artifacts {\n        archives jarTask\n    }\n}\n\nsourceSets {\n    api\n    impl\n}\n\njar {\n    from sourceSets.api.output\n    from sourceSets.impl.output\n}\n\nuploadArchives {\n    repositories {\n        mavenDeployer {\n            repository(url: uri(\"${buildDir}\/repo\"))\n\n            addFilter(\"main\") { artifact, file -&gt; artifact.name == project.name }\n            [\"api\", \"impl\"].each { type -&gt;\n                addFilter(type) { artifact, file -&gt; artifact.name.endsWith(\"-$type\") }\n                \n                \/\/ We now have to map our configurations to the correct maven scope for each pom\n                [\"compile\", \"runtime\"].each { scope -&gt;\n                    configuration = configurations[type + scope.capitalize()]\n                    [\"main\", type].each { pomName -&gt;\n                        pom(pomName).scopeMappings.addMapping 1, configuration, scope\n                    }\n                }\n            }\n\n        }\n    }\n}\n<\/pre>\n<p>So, this script has a some tasks configurations, take a look to each:<\/p>\n<ul>\n<li>First we apply java and maven plugins to use the&nbsp;tasks defined in them. See <code>apply plugin<\/code> reference.<\/li>\n<li>The maven repository is referenced&nbsp;to download the libraries with which there are dependencies to compile and run. See <code>repositories<\/code> and <code>dependencies<\/code> reference.<\/li>\n<li>Then, dynamically it&#8217;s defined for each SourceSet a <code>jar<\/code> assembly&nbsp;<code>task<\/code>. In the 25 line, we define 2 tasks, called <code>apiJar<\/code> and <code>implJar<\/code> that both are Jar type and&nbsp;what they do is to assemble the jar with the classes contained for the SourceSets.<\/li>\n<li>In the line 35 we define the new <code>SourceSets<\/code>, <strong>api <\/strong> and <strong>impl<\/strong>, that are contained in the src folder, in next steps we see how to set a custom location.<\/li>\n<li>The <code>Jar<\/code> method in line 40 set the sources that are assembled in the Jar, in this case get all sources from api and impl SourceSets. If we take a look at line 27, for apiJar and implJar tasks, those only has api sources or impl sources but no both, so if them have dependency will occurs compilation or runtime errors using the Jar.<\/li>\n<li>Last method <code>uploadArchives<\/code> will&nbsp;deploy this jar file to a remote Maven repository. For this example we can delete this.<\/li>\n<\/ul>\n<h2>6. SourceSet&#8217;s Properties<\/h2>\n<p>Foremost we will add a task to see all the <code>properties<\/code> of SourceSets, please add it to the end of the script.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\">task sourceSetProperties &lt;&lt; {\n\tsourceSets {\n\t\tmain {\n\t\t\tprintln \"java.srcDirs = ${java.srcDirs}\"\n\t\t\tprintln \"resources.srcDirs = ${resources.srcDirs}\"\n\t\t\tprintln \"java.files = ${java.files.name}\"\n\t\t\tprintln \"allJava.files = ${allJava.files.name}\"\n\t\t\tprintln \"resources.files = ${resources.files.name}\"\n\t\t\tprintln \"allSource.files = ${allSource.files.name}\"\n\t\t\tprintln \"output.classesDir = ${output.classesDir}\"\n\t\t\tprintln \"output.resourcesDir = ${output.resourcesDir}\"\n\t\t\tprintln \"output.files = ${output.files}\"\n\t\t}\n\t}\n}\n<\/pre>\n<p>In this tasks we point to the main SourceSet that&#8217;s set by default. So, then run the task with the command <code>gradle sSP<\/code> (brief invocation) and will see this output:<\/p>\n<pre class=\"brush:bash\">C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject&gt;gradle sSP\n:sourceSetProperties\njava.srcDirs = [C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\src\\main\\ja\nva]\nresources.srcDirs = [C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\src\\ma\nin\\resources]\njava.files = []\nallJava.files = []\nresources.files = []\nallSource.files = []\noutput.classesDir = C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\build\\c\nlasses\\main\noutput.resourcesDir = C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\build\n\\resources\\main\noutput.files = [C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\build\\class\nes\\main, C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\build\\resources\\ma\nin]\n\nBUILD SUCCESSFUL\n\nTotal time: 1.169 secs\n<\/pre>\n<p>The result is, all &#8216;files properties&#8217; are empty because the directories point to the default values <code>src\/main\/java<\/code>. So to make this properties works we can set this task to impl or api SourceSets, or also we can set any as the main SourceSet. If we change <code>main<\/code> for <code>impl <\/code> in 3rd line and run again the task we will see this output.<\/p>\n<pre class=\"brush:bash\">C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject&gt;gradle sSP\n:sourceSetProperties\njava.srcDirs = [C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\src\\impl\\ja\nva]\nresources.srcDirs = [C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\src\\im\npl\\resources]\njava.files = [DoublerImpl.java]\nallJava.files = [DoublerImpl.java]\nresources.files = []\nallSource.files = [DoublerImpl.java]\noutput.classesDir = C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\build\\c\nlasses\\impl\noutput.resourcesDir = C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\build\n\\resources\\impl\noutput.files = [C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\build\\class\nes\\impl, C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\build\\resources\\im\npl]\n\nBUILD SUCCESSFUL\n\nTotal time: 1.265 secs\n<\/pre>\n<p>Gradle this time whether found java files.<\/p>\n<p>Another strategy is to set the main SourceSet point to src&#8217;s root. adding this configuration to SourceSets task. So if we run again the <code>gradle sSP<\/code> command will see all Java sources without test clasess. This is how we customize the&nbsp;SourceSet directory.<\/p>\n<pre class=\"brush:xml;highlight:[4,5,6,7,8,9,10,11,12,13]\">sourceSets {\n    api\n    impl\n\tmain{\n\t\tjava {\n\t\t\tsrcDir 'src\/api\/java'\n\t\t\tsrcDir 'src\/impl\/java'\n\t\t}\n\t}\n\ttest {\n\t\tjava {\n\t\t\tsrcDir 'src\/test\/java'\n\t\t}\n\t}\n}\n<\/pre>\n<pre class=\"brush:bash\">java.srcDirs = [C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\src\\main\\ja\nva, C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject\\src\\api\\java, C:\\Users\\\nAndres\\workspaceLuna\\GradleSourceSetProject\\src\\impl\\java]\njava.files = [Doubler.java, DoublerImpl.java]\nallJava.files = [Doubler.java, DoublerImpl.java]\nresources.files = []\nallSource.files = [Doubler.java, DoublerImpl.java]\n<\/pre>\n<p>We have 3 directories for the main SourceSet, and both classes are contained.<\/p>\n<h2>7. Assembling SourceSets in JAR Files<\/h2>\n<p>So if we want to package the output classes in a new JAR file, it&#8217;s simple we must define a task of <code>Jar type<\/code> and set a key sentence <code>from sourceSet.output<\/code>. In previous steps we already define them, look at 25 line or Jar configuration in line 40. So if we run the inital dinamic tasks gradle apiJar and gradle implJar, Gradle will generate a JAR with the output sources in the directories defined for the task.[ulp id=&#8217;1om4ygalA6VlPl7R&#8217;]<\/p>\n<pre class=\"brush:bash\">C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject&gt;gradle apiJar\n:compileApiJava UP-TO-DATE\n:processApiResources UP-TO-DATE\n:apiClasses UP-TO-DATE\n:apiJar UP-TO-DATE\n\nBUILD SUCCESSFUL\n\nTotal time: 0.997 secs\n<\/pre>\n<p>Gradle automatically will create 3 new tasks based on any new SourceSet added to the project, apiClasses, compileApiJava, and processApiResources for this case, but in other case change api for sourceset&#8217;s name. These tasks&nbsp;have a dependency between them, so what they do in 3 steps is to compile the java files, process resources and assemble the jar copying all the files to it, keeping the project structure.<\/p>\n<p>Then, we assemble the three possible Jar files, so:<\/p>\n<ul>\n<li><code>gradle apiJar<\/code> , only contains api output sources<\/li>\n<li><code>gradle impJar<\/code>,&nbsp;only contains api output sources.<\/li>\n<li><code>gradle Jar<\/code>, contains all output project sources.<\/li>\n<\/ul>\n<p>So refresh the project and take a look in the <code>build\/libs<\/code> directory.<\/p>\n<p><figure id=\"attachment_24239\" aria-describedby=\"caption-attachment-24239\" style=\"width: 575px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sourceset_jars3.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sourceset_jars3.jpg\" alt=\"Gradle SourceSet Jars\" width=\"575\" height=\"777\" class=\"size-full wp-image-24239\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sourceset_jars3.jpg 575w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/gradle_sourceset_jars3-222x300.jpg 222w\" sizes=\"(max-width: 575px) 100vw, 575px\" \/><\/a><figcaption id=\"caption-attachment-24239\" class=\"wp-caption-text\">Gradle SourceSet Jars<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<h2>8.&nbsp;Creating SourceSet Documentation<\/h2>\n<p>So if we want to generate the Javadoc documentation, we must use the javadoc task. This tasks seeks by default the main SourceSet, but with the property&nbsp;<code>sourceSets.&lt;sourceSet&gt;.allJava<\/code> we can add another custom SourceSet. Next, add this task to the build script and we can run the command gradle javadoc; the generated documentation is allocated into <code>build\/docs\/javadoc<\/code>.<\/p>\n<pre class=\"brush:java\">javadoc {\n\t\/\/ but the main sourceset contains both api &amp; impl sourceset, javadoc will generate all documentation\n\tsource sourceSets.api.allJava\n\t}\n<\/pre>\n<pre class=\"brush:bash\">C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject&gt;gradle javadoc\n:compileJava UP-TO-DATE\n:processResources UP-TO-DATE\n:classes UP-TO-DATE\n:javadoc UP-TO-DATE\n\nBUILD SUCCESSFUL\n\nTotal time: 1.321 secs\n<\/pre>\n<p>&nbsp;<\/p>\n<h2>9. Testing<\/h2>\n<p>So&nbsp;for run the Unit test classes contained in the test SourceSet, we need to add this configuration to the <code>test Task<\/code> to view the result of execution.<\/p>\n<pre class=\"brush:java\">test {\n\t\/\/ Print in console the result of test\n\tafterTest { test, result -&gt;\n\t\tprintln \"Executing test ${test.name} [${test.className}] with result: ${result.resultType}\"\n\t}\n}\n<\/pre>\n<p>We run the task, <code>gradle test<\/code> and get this output:<\/p>\n<pre class=\"brush:bash\">C:\\Users\\Andres\\workspaceLuna\\GradleSourceSetProject&gt;gradle test\n:compileApiJava UP-TO-DATE\n:processApiResources UP-TO-DATE\n:apiClasses UP-TO-DATE\n:compileJava UP-TO-DATE\n:processResources UP-TO-DATE\n:classes UP-TO-DATE\n:compileImplJava UP-TO-DATE\n:processImplResources UP-TO-DATE\n:implClasses UP-TO-DATE\n:compileTestJava UP-TO-DATE\n:processTestResources UP-TO-DATE\n:testClasses UP-TO-DATE\n:test\nExecuting test testIt [doubler.impl.DoublerImplTest] with result: SUCCESS\n\nBUILD SUCCESSFUL\n\nTotal time: 1.596 secs\n<\/pre>\n<h2>10.&nbsp;Final Build.Gradle SourceSet Script<\/h2>\n<p>This is the final version of the script.<\/p>\n<pre class=\"brush:java\">\/*\n * Author: Andres Cespedes\n * Date: 01 May 2015\n * Example: Gradle SourceSets Example\n * Site: www.javacodegeeks.com\n * *\/\napply plugin: \"java\"\n\n\/\/Script Version\nversion = 1.0\n\/\/Java version compatibility to use when compiling Java source.\nsourceCompatibility = 1.7\n\/\/Java version to generate classes for.\ntargetCompatibility = 1.7\n\n\/\/repository where to fetch third party libraries and dependencies\nrepositories { mavenCentral() }\n\n\/\/Set a Jar task to all of SourceSets.\nsourceSets.all { set -&gt;\n\tdef jarTask = task(\"${set.name}Jar\", type: Jar) {\n\t\tbaseName = baseName + \"-$set.name\"\n\t\tfrom set.output\n\t}\n\n\tartifacts { archives jarTask }\n}\n\n\/\/Print Main Sourceset Properties\ntask sourceSetProperties &lt;&lt; {\n\tsourceSets {\n\t\tmain {\n\t\t\tprintln \"java.srcDirs = ${java.srcDirs}\"\n\t\t\tprintln \"resources.srcDirs = ${resources.srcDirs}\"\n\t\t\tprintln \"java.files = ${java.files.name}\"\n\t\t\tprintln \"allJava.files = ${allJava.files.name}\"\n\t\t\tprintln \"resources.files = ${resources.files.name}\"\n\t\t\tprintln \"allSource.files = ${allSource.files.name}\"\n\t\t\tprintln \"output.classesDir = ${output.classesDir}\"\n\t\t\tprintln \"output.resourcesDir = ${output.resourcesDir}\"\n\t\t\tprintln \"output.files = ${output.files}\"\n\t\t}\n\t}\n}\n\n\/\/ SourceSet's Configuration\nsourceSets {\n\tapi\n\timpl\n\tmain{\n\t\tjava {\n\t\t\tsrcDir 'src\/api\/java'\n\t\t\tsrcDir 'src\/impl\/java'\n\t\t}\n\t}\n\ttest {\n\t\tjava { srcDir 'src\/test\/java' }\n\t}\n}\n\n\/\/ Compile, Test and Run dependencies\ndependencies {\n\tapiCompile 'commons-codec:commons-codec:1.5'\n\n\timplCompile sourceSets.api.output\n\timplCompile 'commons-lang:commons-lang:2.6'\n\n\ttestCompile 'junit:junit:4.9'\n\ttestCompile sourceSets.api.output\n\ttestCompile sourceSets.impl.output\n\truntime configurations.apiRuntime\n\truntime configurations.implRuntime\n}\n\n\/\/ JAR Task Configuration, define output the directories that make up the file.\njar {\n\tfrom sourceSets.api.output\n\tfrom sourceSets.impl.output\n}\n\njavadoc {\n\t\/\/ but the main sourceset contains both api &amp; impl sourceset, javadoc will generate all documentation\n\tsource sourceSets.api.allJava\n\t}\n\ntest {\n\t\/\/ Print in console the result of test\n\tafterTest { test, result -&gt;\n\t\tprintln \"Executing test ${test.name} [${test.className}] with result: ${result.resultType}\"\n\t}\n}\n<\/pre>\n<h2>11.Key Points<\/h2>\n<div class=\"tip\">\n<p><strong>Tips<\/strong><\/p>\n<ul>\n<li>The Gradle SourceSet&#8217;s Properties are made to access to the directories and files that make up the SourceSet.<\/li>\n<li>Java plugin give us a lot of basic funcionalities to improves the development process.<\/li>\n<li>Gradle have a lot of default values, you need to set the custom values that adjust to your project<\/li>\n<li>Every task have so many properties, that can be useful to your needs but to mantain the article more readable we don&#8217;t mention it here<\/li>\n<li>Gradle SourceSet concept, is an excellent tool to build a clean structure into your project and make software&#8217;s components, atomic pieces that you can manage and assemble.<\/li>\n<\/ul>\n<\/div>\n<h2>12. Download the Eclipse Project<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/GradleSourceSetProject.zip\">Gradle SourceSet Project<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Gradle SourceSets are&nbsp;a key concept for the Gradle Java Plugin which define the structure of Java Source Files. In this example will see how to use this concept, customize them through gradle properties, create a new sourceset, get documentation and assembling them in a JAR. 1. Introduction to Gradle SourceSets 1.1 What is a Gradle &hellip;<\/p>\n","protected":false},"author":37,"featured_media":20342,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[908],"tags":[],"class_list":["post-22912","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gradle"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Gradle SourceSets Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Gradle SourceSets are\u00a0a key concept for the Gradle Java Plugin which define the structure of Java Source Files and how to group a set of java files.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Gradle SourceSets Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Gradle SourceSets are\u00a0a key concept for the Gradle Java Plugin which define the structure of Java Source Files and how to group a set of java files.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-05-05T08:00:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-03T11:02:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andres Cespedes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@acespedes12\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andres Cespedes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/\"},\"author\":{\"name\":\"Andres Cespedes\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a32ee4d7e34cb21bfd2a5a68cf174f8a\"},\"headline\":\"Gradle SourceSets Example\",\"datePublished\":\"2015-05-05T08:00:41+00:00\",\"dateModified\":\"2019-04-03T11:02:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/\"},\"wordCount\":1096,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg\",\"articleSection\":[\"Gradle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/\",\"name\":\"Gradle SourceSets Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg\",\"datePublished\":\"2015-05-05T08:00:41+00:00\",\"dateModified\":\"2019-04-03T11:02:19+00:00\",\"description\":\"Gradle SourceSets are\u00a0a key concept for the Gradle Java Plugin which define the structure of Java Source Files and how to group a set of java files.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Gradle\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/gradle\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Gradle SourceSets Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a32ee4d7e34cb21bfd2a5a68cf174f8a\",\"name\":\"Andres Cespedes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Andres-Cespedes_avatar_1418741113-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Andres-Cespedes_avatar_1418741113-96x96.jpg\",\"caption\":\"Andres Cespedes\"},\"description\":\"Andres is a Java Software Craftsman from Medellin Colombia, who strongly develops on DevOps practices, RESTful Web Services, Continuous integration and delivery. Andres is working to improve software process and modernizing software culture on Colombia.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\",\"http:\/\/co.linkedin.com\/in\/andrespedes12\",\"https:\/\/x.com\/acespedes12\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/andres-cespedes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Gradle SourceSets Example - Java Code Geeks","description":"Gradle SourceSets are\u00a0a key concept for the Gradle Java Plugin which define the structure of Java Source Files and how to group a set of java files.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/","og_locale":"en_US","og_type":"article","og_title":"Gradle SourceSets Example - Java Code Geeks","og_description":"Gradle SourceSets are\u00a0a key concept for the Gradle Java Plugin which define the structure of Java Source Files and how to group a set of java files.","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-05-05T08:00:41+00:00","article_modified_time":"2019-04-03T11:02:19+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg","type":"image\/jpeg"}],"author":"Andres Cespedes","twitter_card":"summary_large_image","twitter_creator":"@acespedes12","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Andres Cespedes","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/"},"author":{"name":"Andres Cespedes","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a32ee4d7e34cb21bfd2a5a68cf174f8a"},"headline":"Gradle SourceSets Example","datePublished":"2015-05-05T08:00:41+00:00","dateModified":"2019-04-03T11:02:19+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/"},"wordCount":1096,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg","articleSection":["Gradle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/","name":"Gradle SourceSets Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg","datePublished":"2015-05-05T08:00:41+00:00","dateModified":"2019-04-03T11:02:19+00:00","description":"Gradle SourceSets are\u00a0a key concept for the Gradle Java Plugin which define the structure of Java Source Files and how to group a set of java files.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-sourcesets-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"Gradle","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/gradle\/"},{"@type":"ListItem","position":5,"name":"Gradle SourceSets Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a32ee4d7e34cb21bfd2a5a68cf174f8a","name":"Andres Cespedes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Andres-Cespedes_avatar_1418741113-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Andres-Cespedes_avatar_1418741113-96x96.jpg","caption":"Andres Cespedes"},"description":"Andres is a Java Software Craftsman from Medellin Colombia, who strongly develops on DevOps practices, RESTful Web Services, Continuous integration and delivery. Andres is working to improve software process and modernizing software culture on Colombia.","sameAs":["http:\/\/www.javacodegeeks.com\/","http:\/\/co.linkedin.com\/in\/andrespedes12","https:\/\/x.com\/acespedes12"],"url":"https:\/\/examples.javacodegeeks.com\/author\/andres-cespedes\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/22912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=22912"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/22912\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/20342"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=22912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=22912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=22912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}