{"id":76629,"date":"2018-05-08T07:00:39","date_gmt":"2018-05-08T04:00:39","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=76629"},"modified":"2018-05-07T15:48:02","modified_gmt":"2018-05-07T12:48:02","slug":"gradle-tutorial","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html","title":{"rendered":"Gradle Tutorial"},"content":{"rendered":"<h2 id=\"introduction\">1. Introduction<\/h2>\n<p>In this lesson, we will study about <a href=\"https:\/\/gradle.org\/\">Gradle<\/a>, which is a build tool and a dependency management system very similar to <a href=\"https:\/\/examples.javacodegeeks.com\/enterprise-java\/maven\/maven-tutorial-for-beginners\/\" target=\"_blank\" rel=\"noopener\">Maven<\/a> and <a href=\"https:\/\/examples.javacodegeeks.com\/core-java\/apache\/ant\/apache-ant-tutorial-beginners\/\" target=\"_blank\" rel=\"noopener\">Ant<\/a> and designed specifically for building Java-based projects.<\/p>\n<p>Unlike Maven and Ant build systems, Gradle doesn&#8217;t use XML. It is actually built in DSL based on <a href=\"http:\/\/groovy-lang.org\/\" target=\"_blank\" rel=\"noopener\">Groovy<\/a>. The biggest advantage Groovy-based Gradle scripts provided was to make much smaller and concise build scripts as compared to other build systems which were based on XML. Just like a Maven build file is called <code>pom.xml<\/code>, Gradle&#8217;s configuration file is called <code>build.gradle<\/code> by convention. In this lesson, we will study about core Gradle concepts and also set up a simple project based on Spring Boot. Even if you&#8217;re not a Spring Developer, you can still follow along as the lesson is defined in such a way that a framework doesn&#8217;t introduce any hindrance in your learning the Gradle concepts. Let&#8217;s start the action!<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#core_concepts\">2. Gradle Core Concepts<\/a><\/dt>\n<dt><a href=\"#install_gradle\">3. Installing Gradle<\/a><\/dt>\n<dt><a href=\"#setup_project\">4. Setting up a Sample Projec<\/a><\/dt>\n<dt><a href=\"#run_gradle\">5. Running Gradle<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#run_task\">5.1 Running a Task<\/a><\/dt>\n<dt><a href=\"#run_multiple_task\">5.2 Running Multiple Tasks<\/a><\/dt>\n<dt><a href=\"#name_abbreviation\">5.3 Task Name Abbreviation<\/a><\/dt>\n<dt><a href=\"#exclude_task\">5.4 Excluding Tasks<\/a><\/dt>\n<dt><a href=\"#quiet_mode\">5.5 Quiet Mode<\/a><\/dt>\n<dt><a href=\"#list_task\">5.6 Listing Tasks in Build Script<\/a><\/dt>\n<dt><a href=\"#specify_script\">5.7 Explicitly Specifying Build Script<\/a><\/dt>\n<dt><a href=\"#specify_project\">5.8 Specifying Project<\/a><\/dt>\n<dt><a href=\"#list_subproject\">5.9 Listing Subprojects<\/a><\/dt>\n<dt><a href=\"#gradle_help\">5.10 Gradle Help<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#define_using_task\">6. Defining and Using Gradle Tasks<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#define_task\">6.1 Defining Gradle Tasks<\/a><\/dt>\n<dt><a href=\"#task_execution\">6.2 Task Execution Phases<\/a><\/dt>\n<dt><a href=\"#shorter_syntax\">6.3 Shorter Syntax for Task definition<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#always_quiet_mode\">7. Always running Gradle in Quiet Mode<\/a><\/dt>\n<dt><a href=\"#extend_boot_project\">8. Extending Java Spring Boot Project<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#define_controller\">8.1 Defining a Controller<\/a><\/dt>\n<dt><a href=\"#task_execution\">8.2 Running the Project with Gradle<\/a><\/dt>\n<dt><a href=\"#try_api\">8.3 Trying the APIs<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#gradle_wrapper\">9. Gradle Wrapper<\/a><\/dt>\n<dt><a href=\"#ant_maven_gradle\">10. Ant vs Maven vs Gradle<\/a><\/dt>\n<dt><a href=\"#conclusion\">11. Conclusion<\/a><\/dt>\n<dt><a href=\"#download\">12. Download the Source Code<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2 id=\"core_concepts\">2. Gradle Core Concepts<\/h2>\n<p>The core concepts behind Gradle build system can be listed down to three main features. They are:<\/p>\n<ol>\n<li>Projects: A software which you want to build<\/li>\n<li>Tasks: These are actions which actually build the project<\/li>\n<li>Build-scripts: This is the script which contains Tasks which build the project<\/li>\n<\/ol>\n<p>To understand the relationship between each of them, let&#8217;s study them together. So, a project is something you want to build. The tasks are the actions which build the project. To be specific, there can be tasks to compile the source code, making an executable file like a WAR or a JAR file. A Gradle-based project can contain any number of tasks to execute in order to build the project.<\/p>\n<p>The <strong>tasks are defined inside a build script file<\/strong> which can be executed by Gradle to run each task in a specified order. It is even possible to pick a particular task with the <code>gradle<\/code> command to run only the specified task. These tasks are defined in the <code>build.script<\/code> file which is present in the root directory of the project. Usually, we only have a <strong>single build file<\/strong> for a project.<\/p>\n<h2 id=\"install_gradle\">3. Installing Gradle<\/h2>\n<p>Before we can start playing with Gradle commands and start defining Gradle tasks, we must install Gradle on our system. Please note that the Gradle needs JDK 6 or above to be run. Gradle will use the Java JDK which it finds on your system&#8217;s PATH environment as <code>JAVA_HOME<\/code>. If you want a Java version apart from what you actually use, just make the <code>JAVA_HOME<\/code> environment variable points to that version of Java and Gradle will start using it. You can make sure that Java is installed on your system with this simple command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Check Java version<\/em><\/span><\/p>\n<pre class=\"brush:bash\">java -version\r\n<\/pre>\n<p>You should see something like this:<\/p>\n<p><figure id=\"attachment_76633\" aria-describedby=\"caption-attachment-76633\" style=\"width: 602px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/java-version.png\"><img decoding=\"async\" class=\"size-full wp-image-76633\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/java-version.png\" alt=\"Check java version\" width=\"602\" height=\"217\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/java-version.png 602w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/java-version-300x108.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/a><figcaption id=\"caption-attachment-76633\" class=\"wp-caption-text\">Check java version<\/figcaption><\/figure><\/p>\n<p>Once the Java version is confirmed, <a href=\"https:\/\/gradle.org\/install\/\" target=\"_blank\" rel=\"noopener\">download<\/a> the version of Gradle you want to install, and unzip it into the directory you want Gradle installed in. When Gradle is extracted into the install directory, add the <code>DIRECTCRY_PATH\/bin<\/code> to the PATH environment variable. The <code>DIRECTCRY_PATH<\/code> part of the added path must be the full path to the Gradle install directory (and not &#8220;DIRECTCRY_PATH&#8221; as text). Once this is done, we can check the Gradle version the same way we did for Java, with the following command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Check Gradle version<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle -version\r\n<\/pre>\n<p>You should see something like this:<\/p>\n<p><figure id=\"attachment_76638\" aria-describedby=\"caption-attachment-76638\" style=\"width: 714px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-version.png\"><img decoding=\"async\" class=\"size-full wp-image-76638\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-version.png\" alt=\"Gradle version\" width=\"714\" height=\"521\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-version.png 714w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-version-300x219.png 300w\" sizes=\"(max-width: 714px) 100vw, 714px\" \/><\/a><figcaption id=\"caption-attachment-76638\" class=\"wp-caption-text\">Gradle version<\/figcaption><\/figure><\/p>\n<p>Even though we have already installed Gradle, you can follow along with the lesson even if you do not install Gradle and make a sample project as we describe in our next section. The gradle build script will be self-contained in that project and won&#8217;t need an explicit installation of Gradle on the system itself. Isn&#8217;t that excellent?!<\/p>\n<h2 id=\"setup_project\">4. Setting up a Sample Project<\/h2>\n<p>We will be using one of the most popular web tool to make a sample project in this lesson and won\u2019t do it from the command line, we will make use of <a href=\"https:\/\/start.spring.io\/\" target=\"_blank\" rel=\"noopener\">Spring Initializr<\/a>. Just open the link in your browser and explore around. To setup our project, we used the following configuration:<\/p>\n<p><figure id=\"attachment_76635\" aria-describedby=\"caption-attachment-76635\" style=\"width: 768px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-setup.png\"><img decoding=\"async\" class=\"size-full wp-image-76635\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-setup.png\" alt=\"Spring Initializr config\" width=\"768\" height=\"844\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-setup.png 768w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/project-setup-273x300.png 273w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/a><figcaption id=\"caption-attachment-76635\" class=\"wp-caption-text\">Spring Initializr config<\/figcaption><\/figure><\/p>\n<p>We added a single dependency as shown and it doesn&#8217;t really matter. Unzip the project and open <code>build.gradle<\/code> file present in the root directory of the project in any text editor you like. For this project, the file will look like:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>build.gradle<\/em><\/span><\/p>\n<pre class=\"brush:bash\">buildscript {\r\n\text {\r\n\t\tspringBootVersion = '2.0.1.RELEASE'\r\n\t}\r\n\trepositories {\r\n\t\tmavenCentral()\r\n\t}\r\n\tdependencies {\r\n\t\tclasspath(\"org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}\")\r\n\t}\r\n}\r\n\r\napply plugin: 'java'\r\napply plugin: 'eclipse'\r\napply plugin: 'org.springframework.boot'\r\napply plugin: 'io.spring.dependency-management'\r\n\r\ngroup = 'com.javacodegeeks.example'\r\nversion = '0.0.1-SNAPSHOT'\r\nsourceCompatibility = 1.8\r\n\r\nrepositories {\r\n\tmavenCentral()\r\n}\r\n\r\ndependencies {\r\n\tcompile('org.springframework.boot:spring-boot-starter-web')\r\n\ttestCompile('org.springframework.boot:spring-boot-starter-test')\r\n}\r\n<\/pre>\n<p>In the script file above, we see that some plugins were specified in the file.\u00a0The first plugin we made use of is the Java plugin. This plugin provides some predefined configurations and tasks that enable us to build a java project very easily. It makes use of Maven-like source sets to find the source code in the specified project.<\/p>\n<p id=\"aed3\" class=\"graf graf--p graf-after--p\">A\u00a0<strong class=\"markup--strong markup--p-strong\">Source-Set<\/strong>\u00a0is defined as a configuration that informs the plugin of\u00a0where to look for the source code for compiling and testing tasks. By default, the Java source code is found under\u00a0<strong class=\"markup--strong markup--p-strong\">src\/main\/java\u00a0<\/strong>and the test packages can be found under\u00a0<strong>src\/test\/java<\/strong>. The same directories will be searched for the source code unless stated otherwise.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Apart from the plugin, we also added some <em>dependencies<\/em> to our project as well. Gradle knows where to look for these dependencies from the\u00a0<em>repositories<\/em> section we defined. We specified that for any dependency resolution, Gradle should refer to the <a href=\"http:\/\/search.maven.org\/\" target=\"_blank\" rel=\"noopener\">Maven central<\/a> repository to download any needed JARs it needs to run the project.<\/p>\n<h2 id=\"run_gradle\">5. Running Gradle<\/h2>\n<p>Open a command-line terminal and change to the root directory of the project. As this project is Gradle based and we have install Gradle on our system as well, we can run Gradle now. Let\u2019s look at how this can be done:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Running Gradle<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle\r\n<\/pre>\n<p>This will run Gradle on the <code>build.gradle<\/code> file present in the root directory of the project.<\/p>\n<h3 id=\"run_task\">5.1 Running a Task<\/h3>\n<p>The Gradle build script contains one or more tasks which we can execute. We can execute a task on the project by simply putting the task name after the gradle command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Running single tasks<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle compileCode\r\n<\/pre>\n<p>The above command will trigger the mentioned task to compile the code for the project. As we mentioned earlier, Gradle will be able to find the source code of the project due to the presence of the apporpriate java plugin in the build file.<\/p>\n<h3 id=\"run_multiple_task\">5.2 Running Multiple Tasks<\/h3>\n<p>Just like we executed a single task in the previous section by putting the task name after the gradle command, we can even execute multiple tasks at a single go to execute them in the specified order. Let\u2019s look at how this can be done:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Running Multiple tasks<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle clean build\r\n<\/pre>\n<p>This command will first execute the <code>clean<\/code> task. Once that task is completed, the <code>install<\/code> task will be automatically triggered. Once we run this command, we will see something like:<\/p>\n<p><figure id=\"attachment_76639\" aria-describedby=\"caption-attachment-76639\" style=\"width: 770px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-multiple-tasks.png\"><img decoding=\"async\" class=\"size-full wp-image-76639\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-multiple-tasks.png\" alt=\"Executing multiple tasks\" width=\"770\" height=\"217\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-multiple-tasks.png 770w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-multiple-tasks-300x85.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-multiple-tasks-768x216.png 768w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/a><figcaption id=\"caption-attachment-76639\" class=\"wp-caption-text\">Executing multiple tasks<\/figcaption><\/figure><\/p>\n<p>Just to make a point, even if you mention the same task multiple times, the task will be executed only one time. Like in following command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Running Multiple tasks<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle clean clean\r\n<\/pre>\n<p>Even if the <code>clean<\/code> task is mentioned more than once, it will only be executed once and not twice.<\/p>\n<h3 id=\"name_abbreviation\">5.3 Task Name Abbreviation<\/h3>\n<p>It is not necessary that you type the complete task name to execute it. Like, for the <code>clean<\/code> task, we can write:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Task Abbreviation<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle c\r\n<\/pre>\n<p>If there are no conflicts in name with other tasks, gradle will find the clean task and execute it. When we ran this, it failed as more than one tasks started with the character <code>c<\/code>:<\/p>\n<p><figure id=\"attachment_76641\" aria-describedby=\"caption-attachment-76641\" style=\"width: 770px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-task-abbreviation.png\"><img decoding=\"async\" class=\"size-full wp-image-76641\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-task-abbreviation.png\" alt=\"Task Abbreviation\" width=\"770\" height=\"350\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-task-abbreviation.png 770w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-task-abbreviation-300x136.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-task-abbreviation-768x349.png 768w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/a><figcaption id=\"caption-attachment-76641\" class=\"wp-caption-text\">Task Abbreviation<\/figcaption><\/figure><\/p>\n<p>The error clearly states that the possible candidates are: &#8216;check&#8217;, &#8216;classes&#8217;, &#8216;clean&#8217;, &#8216;components&#8217;. So, we need to be more specific in this case. The following command will work fine though:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Task Abbreviation<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle cle\r\n<\/pre>\n<p>This will execute the <code>clean<\/code> task. This way, Gradle provides a way to be friendly to developers even by providing esy conventions and command-line utilities and we don&#8217;t have to do anything manually shorten our commands.<\/p>\n<h3 id=\"exclude_task\">5.4 Excluding Tasks<\/h3>\n<p>There are Gradle tasks which depend on other tasks as well. So, when you execute a primary task, it will trigger execution of all the tasks it depends on. Although this creates no issue but this slows down the build process. Consider a case when you want to execute the build task. It will trigger <code>test<\/code> and <code>testClasses<\/code> tasks as well but you know that <code>test<\/code> task will succeed as you just tested all the test cases, so you might want to ignore it to speed up the process. This can be done with the <code>-x<\/code> switch as shown:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Ignoring Tasks<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle build -x test\r\n<\/pre>\n<h3 id=\"quiet_mode\">5.5 Quiet Mode<\/h3>\n<p>Gradle, when executing a task, prints a lot of messages to the console. If you want a little and quiet task execution, we can use the <code>-q<\/code> switch as shown to quietly execute the task with no console messages:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Quiet Mode<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle -q compileCode\r\n<\/pre>\n<p>Quiet mode is useful when you write scripts to deploy your project using automated build and deployment files or code pipelines. This way, the log files are not populated with unnecessary log messages produced during gradle task execution.<\/p>\n<h3 id=\"list_task\">5.6 Listing Tasks in Build Script<\/h3>\n<p>When we want to list all tasks which are presented in a build script, we can simply run the following command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>List all tasks<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle tasks\r\n<\/pre>\n<p>For our project, we will see that we have a lot of tasks defined already:<\/p>\n<p><figure id=\"attachment_76644\" aria-describedby=\"caption-attachment-76644\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/list-gradle-tasks.png\"><img decoding=\"async\" class=\"size-full wp-image-76644\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/list-gradle-tasks.png\" alt=\"List all available Gradle Tasks\" width=\"820\" height=\"668\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/list-gradle-tasks.png 820w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/list-gradle-tasks-300x244.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/list-gradle-tasks-768x626.png 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-76644\" class=\"wp-caption-text\">List all available Gradle Tasks<\/figcaption><\/figure><\/p>\n<p>We see information related to each task. This provides a handy way where we get information to each task that was pre-defined into the plugins we defined in the script.<\/p>\n<h3 id=\"specify_script\">5.7 Explicitly Specifying Build Script<\/h3>\n<p>Even though Gradle automatically picks the default build.gradle file in the root directory of the project, if you want to name the file otherwise, it is possible to provide a name to the gradle name for the file you want it to pick as configuration file with the help of <code>-b<\/code> switch:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle -b build.gradle build\r\n<\/pre>\n<h3 id=\"specify_project\">5.8 Specifying Project<\/h3>\n<p>If the project you&#8217;re building contains a subproject you want to build in a standalone mode, you can even specify the project to be executed with the <code>-p<\/code> option:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Execute Subprojects<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle -p subproject-directory build\r\n<\/pre>\n<h3 id=\"list_subproject\">5.9 Listing Subprojects<\/h3>\n<p>We can list all subprojects contained in our main project (as specified inside the Gradle build script for the project) with a simple command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Listing Subprojects<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle projects\r\n<\/pre>\n<p>This command comes handy when you&#8217;re looking at public projects and want to identify what all subprojects are included in the project.<\/p>\n<h3 id=\"gradle_help\">5.10 Gradle Help<\/h3>\n<p>If you need help related to any gradle command and tasks, we can run a simple command to obtain information about various tasks and commands we can execute:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle -h\r\n<\/pre>\n<p>We will present the detailed list of options we have for Gradle command:<\/p>\n<p><figure id=\"attachment_76646\" aria-describedby=\"caption-attachment-76646\" style=\"width: 746px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-help.png\"><img decoding=\"async\" class=\"size-full wp-image-76646\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-help.png\" alt=\"Gradle Help\" width=\"746\" height=\"673\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-help.png 746w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/gradle-help-300x271.png 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/a><figcaption id=\"caption-attachment-76646\" class=\"wp-caption-text\">Gradle Help<\/figcaption><\/figure><\/p>\n<h2 id=\"define_using_task\">6. Defining and Using Gradle Tasks<\/h2>\n<p>Gradle tasks define the actions needed to build a project. Without tasks, our build script will not build anything when Gradle executes it. Now, we will see how we can make our own tasks in the project we already defined above.<\/p>\n<h3 id=\"define_task\">6.1 Defining Gradle Tasks<\/h3>\n<p>Let&#8217;s define a new Gradle Task in the <code>build.gradle<\/code> file as shown:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>build.gradle<\/em><\/span><\/p>\n<pre class=\"brush:bash\">task hello { \r\n    println \"Hello, JavaCodeGeeks.\" \r\n}\r\n<\/pre>\n<p>We can execute the task we defined as:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Running our task<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle hello\r\n<\/pre>\n<p>We will see the output as:<\/p>\n<p><figure id=\"attachment_76652\" aria-describedby=\"caption-attachment-76652\" style=\"width: 592px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/running-own-task.png\"><img decoding=\"async\" class=\"size-full wp-image-76652\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/running-own-task.png\" alt=\"Running our own Task in Gradle\" width=\"592\" height=\"207\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/running-own-task.png 592w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/running-own-task-300x105.png 300w\" sizes=\"(max-width: 592px) 100vw, 592px\" \/><\/a><figcaption id=\"caption-attachment-76652\" class=\"wp-caption-text\">Running our own Task in Gradle<\/figcaption><\/figure><\/p>\n<h3 id=\"task_execution\">6.2 Task Execution Phases<\/h3>\n<p>When a Gradle task is executed, it passes through two execution phases before the result is evaluated. These phases are:<\/p>\n<ul>\n<li>first<\/li>\n<li>last<\/li>\n<\/ul>\n<p>Internally, a Gradle task is represented as an Object. To start the execution of the first phase, we must call one of the defined methods, passing a closure as a parameter (a closure is an anonymous function). The respective build phase methods are:<\/p>\n<ul>\n<li>doFirst()<\/li>\n<li>doLast()<\/li>\n<\/ul>\n<p>Let&#8217;s look at an example on how to call these two methods in a task:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Call Phase methods<\/em><\/span><\/p>\n<pre class=\"brush:bash\">task hello\r\n\r\nhello.doFirst({\r\n\tprintln \"First method\"\r\n});\r\n\r\nhello.doLast({\r\n\tprintln \"Last method\"\r\n});\r\n<\/pre>\n<p>When we execute these methods using the command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Running our task<\/em><\/span><\/p>\n<pre class=\"brush:bash\">gradle hello\r\n<\/pre>\n<p>We will see the output as:<\/p>\n<p><figure id=\"attachment_76651\" aria-describedby=\"caption-attachment-76651\" style=\"width: 599px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/add-new-task-gradle.png\"><img decoding=\"async\" class=\"size-full wp-image-76651\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/add-new-task-gradle.png\" alt=\"Running our own Task in Gradle\" width=\"599\" height=\"217\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/add-new-task-gradle.png 599w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/add-new-task-gradle-300x109.png 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/a><figcaption id=\"caption-attachment-76651\" class=\"wp-caption-text\">Running Phased Task<\/figcaption><\/figure><\/p>\n<p>As we saw earlier, we first defined a task called hello. Next, we defined and called the <code>doFirst()<\/code> method and passed a closure as parameter which contains a print statement. Similarly defined the next method <code>doLast()<\/code> which essentially do the same thing. When we run the task, we can see these two methods being called in the same order.<\/p>\n<h3 id=\"shorter_syntax\">6.3 Shorter Syntax for Task definition<\/h3>\n<p>With Groovy, possibilities of optimizing a code is much higher than other languages. Same is possible with the phased task definition we wrote in the previous section. Here are the improvements we can perform on the code we defined:<\/p>\n<ul>\n<li>No need of semi-colon at the end of each method definition, if the code line with the method calls ends with a new line.<\/li>\n<li>As the closure are anonymous functions, we do not need the parentheses around the statements which are present in a closure.<\/li>\n<\/ul>\n<p>With these optimizations, our code will look like:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Call Phase methods<\/em><\/span><\/p>\n<pre class=\"brush:bash\">task hello\r\n\r\nhello.doFirst{\r\n\tprintln \"First method\"\r\n}\r\n\r\nhello.doLast{\r\n\tprintln \"Last method\"\r\n}\r\n<\/pre>\n<p>The output for this execution phase will, of course, remain the same as earlier. You will most often see the shorter syntax in the official Gradle documentation and in other Gradle tutorials as well because it is much more direct and concise.<\/p>\n<h2 id=\"always_quiet_mode\">7. Always running Gradle in Quiet Mode<\/h2>\n<p>Running Gradle in Quiet mode is not possible currently\u00a0after the build has started. We can find the current value but it&#8217;s read-only by the time we can execute any code.<\/p>\n<p>The LogLevel can be accessed via the gradle object in scripts by it&#8217;s <code>startParamater<\/code>:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Get Gradle Log level<\/em><\/span><\/p>\n<pre class=\"brush:bash\">LogLevel level = gradle.startParameter.logLevel\r\nprintln \"Current logging level: $level\"\r\n<\/pre>\n<p>If we want to have logging that isn&#8217;t always sent to the console then we could use Gradle&#8217;s built-in logger:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Print on INFO only<\/em><\/span><\/p>\n<pre class=\"brush:bash\">project.logger.info(\"This gets printed only if caller uses --info flag on command line.\")\r\n<\/pre>\n<p>Then for our events, we want the console logger to use the\u00a0<code>lifecycle<\/code>\u00a0level:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Message always printed<\/em><\/span><\/p>\n<pre class=\"brush:bash\">project.logger.lifecycle('my message that will always print')\r\n<\/pre>\n<h2 id=\"extend_boot_project\">8. Extending Java Spring Boot Project<\/h2>\n<p>In this section, we will add minor Java code in the project we set up and see how we can run it using the build script and the Gradle wrapper that came with the project itself. If you open the project in your favourite IDE, you will see that it only contains a single class with following code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>JcgGradleTutorialApplication.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.example.JCGGradleTutorial;\r\n\r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\n\r\n@SpringBootApplication\r\npublic class JcgGradleTutorialApplication {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSpringApplication.run(JcgGradleTutorialApplication.class, args);\r\n\t}\r\n}\r\n<\/pre>\n<p>We will be modifying this class in the next section to make it a full-fledged <a href=\"https:\/\/www.javacodegeeks.com\/2018\/04\/spring-boot-tutorial.html\" target=\"_blank\" rel=\"noopener\">Spring Boot<\/a> project.<\/p>\n<h3 id=\"define_controller\">8.1 Defining a Controller<\/h3>\n<p>We will be making minor modifications in the class we defined above to turn it into a full-fledged Spring Boot controller class so that we define APIs into it as well. Here is the code we will use:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>JcgGradleTutorialApplication.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.example.JCGGradleTutorial;\r\n\r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@SpringBootApplication\r\n@RestController\r\npublic class JcgGradleTutorialApplication {\r\n\r\n  public static void main(String[] args) {\r\n    SpringApplication.run(JcgGradleTutorialApplication.class, args);\r\n  }\r\n\r\n  @RequestMapping(value = \"\")\r\n  public String helloWorld() {\r\n    return \"Hello Java Geek!\";\r\n  }\r\n}\r\n<\/pre>\n<p>Now that the Controller is ready, we can move on to run the project. Also, for a deeper understanding of how Sprint Boot project and Controllers work, read the\u00a0<a href=\"https:\/\/www.javacodegeeks.com\/2018\/04\/spring-boot-tutorial.html\" target=\"_blank\" rel=\"noopener\">Spring Boot Tutorial<\/a>.<\/p>\n<h3 id=\"run_project\">8.2 Running the Project with Gradle<\/h3>\n<p>The project we downloaded comes with a Gradle wrapper. This wrapper contains Gradle scripts which can be used to run the project even if Gradle is not installed in the system we are running the project on. We can run the project using the following command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Running the project<\/em><\/span><\/p>\n<pre class=\"brush:bash\">.\/gradlew spring-boot:run\r\n<\/pre>\n<p>Just note that before we run the project, remove the task we defined as it can alter other tasks and you might not be able to run the project. Once this is done, we can try the API we just made in the next section.<\/p>\n<h3 id=\"try_api\">8.3 Trying the APIs<\/h3>\n<p>Once the project is up and running, visit the following URL:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Project URL<\/em><\/span><\/p>\n<pre class=\"brush:bash\">localhost:8080\r\n<\/pre>\n<p>We will see the message:<\/p>\n<p><figure id=\"attachment_76655\" aria-describedby=\"caption-attachment-76655\" style=\"width: 480px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/running-project.png\"><img decoding=\"async\" class=\"size-full wp-image-76655\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/running-project.png\" alt=\"Running Project\" width=\"480\" height=\"279\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/running-project.png 480w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/running-project-300x174.png 300w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><figcaption id=\"caption-attachment-76655\" class=\"wp-caption-text\">Running Project<\/figcaption><\/figure><\/p>\n<p>Excellent! With a single command, we were able to run the complete Spring boot project we defined with few lines of code.<\/p>\n<h2 id=\"gradle_wrapper\">9. Gradle Wrapper<\/h2>\n<p>For the easy execution of projects, Gradle also provides a wrapper so that we don&#8217;t have to install Gradle on every machine where we install and run projects which are built on top of Gradle build system. Just like the project we defined above, it contains some files which are Gradle wrappers for various Operating Systems like:<\/p>\n<ul>\n<li><em>gradlew\u00a0<\/em>is the\u00a0shell script file that executes the Gradle tasks<\/li>\n<li>gradlew.bat<em> file is the\u00a0Windows batch script that executes the Gradle tasks<\/em><\/li>\n<li><em>.\/gradle<\/em>\u00a0is a directory which contains a Gradle wrapper JAR and a properties file indicating the version we are using and other configurations. This explicit definition of version makes sure that any updates to Gradle don&#8217;t break this project<\/li>\n<\/ul>\n<p>To run the project using the Gradle wrapper file, just run the\u00a0<em>gradlew<\/em> file if you are using Linux\/OSX or the\u00a0<em>gradlew.bat<\/em> file if you are using windows OS. Another <code>advantageGradle<\/code> wrapper provides is that if we want to switch to a newer version of Gradle, we only need to change an entry in <code>gradle-wrapper.properties<\/code>.<\/p>\n<h2 id=\"ant_maven_gradle\">10. Ant vs Maven vs Gradle<\/h2>\n<p>The three most popular build systems which are used across the industry are Ant, Maven and Gradle. When it comes to comparing these systems, each one stands with its own pros and cons. Let&#8217;s run a quick check with each of these systems to see where there power lies.<\/p>\n<p><strong>Ant\u00a0<\/strong>was released in the year 2000 and was easy to learn and implement. It followed the XML script format and was having a clear drawback was that the XML is\u00a0hierarchical in nature which was <strong>not considered a good fit for procedural programming<\/strong> approach. Also, an XML file with Ant tends to grow big even with a relatively smaller project.<\/p>\n<p><strong>Maven<\/strong> arrived in 2004 with huge improvements over ANT but it continued usng the XML format for its scripts. The biggest advantage added was a capability to <strong>download the required dependencies over a network<\/strong>. The community felt that customaization of goal targets was still difficult and dependency management <strong>doesn&#8217;t handle conflicts<\/strong> well when the same library was downloaded multiple times with different versions.<\/p>\n<p><strong>Gradle<\/strong> was released in 2012 and it gained a lot of traction when Google adopted it as the\u00a0default build tool for the Android OS. Gradle does not use XML. Instead, it had its own DSL based on Groovy (one of JVM languages). As a result, Gradle build scripts tend to be much shorter and clearer than those written for Ant or Maven. Due to the presence of its own dependency resolution engine and huge improvements over the years, its <strong>builds are becoming comparitively faster<\/strong> than Maven and Ant.<\/p>\n<h2 id=\"conclusion\">11. Conclusion<\/h2>\n<p>In this lesson, we studied about how Gradle is one of the most popular and easy-to-use build system and dependency management system used for Java projects. The ease Gradle provides comes with the idea that it was defined specifically for domain related projects only and that is why it provides us with the power to define build scripts which are small in size and can perform so many operations with very few lines of Groovy code inside it.<\/p>\n<p>We also compared Gradle with other build systems which Gradle challenges, which are Maven and Ant. Each of the mentioned build systems has their own pros and cons but the concise nature of Gradle scripts is what can take it a long way to production-grade systems.<\/p>\n<h2 id=\"download\">12. Download the Source Code<\/h2>\n<p>This was an example of Gradle and Task definitions.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <strong><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/05\/JCG-Gradle-Tutorial.zip\" target=\"_blank\" rel=\"noopener\">JCG-Gradle-Tutorial<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In this lesson, we will study about Gradle, which is a build tool and a dependency management system very similar to Maven and Ant and designed specifically for building Java-based projects. Unlike Maven and Ant build systems, Gradle doesn&#8217;t use XML. It is actually built in DSL based on Groovy. The biggest advantage &hellip;<\/p>\n","protected":false},"author":20016,"featured_media":129,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[484],"class_list":["post-76629","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-gradle"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Gradle Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction In this lesson, we will study about Gradle, which is a build tool and a dependency management system very similar to Maven and Ant and\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Gradle Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction In this lesson, we will study about Gradle, which is a build tool and a dependency management system very similar to Maven and Ant and\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-08T04:00:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/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=\"Shubham Aggarwal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shubham Aggarwal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html\"},\"author\":{\"name\":\"Shubham Aggarwal\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0953481a8babbb7a63907edb41f357ad\"},\"headline\":\"Gradle Tutorial\",\"datePublished\":\"2018-05-08T04:00:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html\"},\"wordCount\":3292,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/gradle-logo.jpg\",\"keywords\":[\"Gradle\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html\",\"name\":\"Gradle Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/gradle-logo.jpg\",\"datePublished\":\"2018-05-08T04:00:39+00:00\",\"description\":\"1. Introduction In this lesson, we will study about Gradle, which is a build tool and a dependency management system very similar to Maven and Ant and\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/gradle-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/gradle-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/gradle-tutorial.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Gradle Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0953481a8babbb7a63907edb41f357ad\",\"name\":\"Shubham Aggarwal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g\",\"caption\":\"Shubham Aggarwal\"},\"description\":\"Shubham is a Java EE Engineer with about 3 years of experience in building quality products with Spring Boot, Spring Data, AWS, Kafka, PrestoDB.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sbmaggarwal\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/shubham-aggarwal\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Gradle Tutorial - Java Code Geeks","description":"1. Introduction In this lesson, we will study about Gradle, which is a build tool and a dependency management system very similar to Maven and Ant and","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:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html","og_locale":"en_US","og_type":"article","og_title":"Gradle Tutorial - Java Code Geeks","og_description":"1. Introduction In this lesson, we will study about Gradle, which is a build tool and a dependency management system very similar to Maven and Ant and","og_url":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-05-08T04:00:39+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/gradle-logo.jpg","type":"image\/jpeg"}],"author":"Shubham Aggarwal","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Shubham Aggarwal","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html"},"author":{"name":"Shubham Aggarwal","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0953481a8babbb7a63907edb41f357ad"},"headline":"Gradle Tutorial","datePublished":"2018-05-08T04:00:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html"},"wordCount":3292,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/gradle-logo.jpg","keywords":["Gradle"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html","url":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html","name":"Gradle Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/gradle-logo.jpg","datePublished":"2018-05-08T04:00:39+00:00","description":"1. Introduction In this lesson, we will study about Gradle, which is a build tool and a dependency management system very similar to Maven and Ant and","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/gradle-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/gradle-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/gradle-tutorial.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Gradle Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0953481a8babbb7a63907edb41f357ad","name":"Shubham Aggarwal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g","caption":"Shubham Aggarwal"},"description":"Shubham is a Java EE Engineer with about 3 years of experience in building quality products with Spring Boot, Spring Data, AWS, Kafka, PrestoDB.","sameAs":["https:\/\/www.linkedin.com\/in\/sbmaggarwal\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/shubham-aggarwal"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/76629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/20016"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=76629"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/76629\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/129"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=76629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=76629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=76629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}