Gradle Build Tool Tutorial : Step By Step Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is ashoke and Welcome to our Channel ashoke it in this video we are going to understand what is Gradle how to set up Gradle and how to work with gradel build tool and what is the difference between Maven and gradel before getting started please like this video And subscribe to our channel for more [Music] updates as part of this video we are going to learn what is build tool why we need to go for build tools Maven versus Gradle Gradle setup creating gradel project gradel project folders I mean project structure build scripts and tasks adding the dependencies to the gradel project adding repositories in the gradel project and what is Gradle wrapper and how to build Java projects by using Gradle and conclusion today we are here to disc discuss about the Gradle so what is this Gradle Gradle is an open-source build automation tool this Gradle released in the year of 2007 gradel tool has taken advantages of both ant and Maven and removed disadvantages of both what are the drawbacks available in The Ant and Maven those disadvantages are removed from Gradle whatever the advantages are available Gradle has taken the advantages of them this Gradle tool developed in groovy language but we no need to learn that groovy language to work with the Gradle it developed in The Groovy language gradel tool makes project build automation process easy gradel tool used by large projects like hibernate and spring so Gradle is a build tool what is build tool and what is build process so what are the phases involved in the build process downloading required dependencies what are the jars that are required for our process project we need to download the required dependencies and we need to add the dependencies to the project build path whatever the jars we have downloaded we need to add the jar files to the project build path and we need to compile the source code of the project developers will write the Java files those Java files we can't execute directly we need to compile that source code into do class files once the source code is compiled then we need to execute unit test our project we need to execute unit test of our project once unit tests are executed we need to package the project as a jar file or War file so this is called build process so for every project build process is mandatory build process is going to convert the project source code into executable file by performing above steps we will convert the project to source code into executable file whatever the source code is developed by the developers the that source code we can't execute directly so we need to follow some steps in order to convert that source code into executable file whatever the steps that we are going to follow to convert that source code into executable file that is called as build process in the project developers has to perform this build process in the local and devops Engineers has to perform this build process in the higher environments so as a developer when we are writing the code we need to test our code is working as expected or not in our local system we need to follow the build process once we have done with the coding process then to deploy that codeing to the servers environments devops Engineers has to perform this build process so instead of doing this build process manually we can take the help of build tools to automate the build process so now to automate the above steps in the build process there are several tools available those tools are called as build tools build tools are used to automate build process of the project so what are the build tools that are available in the market earlier people used to work with Y as a build tool after the ant Maven came into picture after the maven Gradle came into picture so what are the build tools available in the market and build tool was very old and outdated build tool after the ant Maven build tool came into picture after the maven Gradle build tool came into picture currently Gradle is having more demand in the market I will explain you why Gradle is having more demand than Maven what are the differences between the maven and Gradle also we are going to understand today so in order to work with the gradel first we need to set up the gradel now gr to set up the gradel Java software is required guys so now check Java is installed or not in your system if Java is not available then you need to install the Java once the Java software is available in your system then download gradel software as a Gip file download gradel software as jip file and extract that jip file once we have extracted that jip file then set the path for Gradle in the environment variables once the path setup is complete for the gradel in the environment variable then check the gradel version really gradel is working or not so how to verify Java is working or not Java Ione version Java iPhone version when I execute Java iPhone version you can see Java version is available in my machine then download gradel software as a Gip file and extract it download gradel grador website is available directly you can go to grador and you can download that and we can install it so just click on binary only when I click on binary only gradel Gip file will be downloaded go to downloads folder so gradel jip file is downloaded okay guys so simply extract that jip file once this extraction got completed go to the gradel folder in that gradel folder you can see bin directory that is gradel DOB so for this gradel bin directory we need to set the path in our environment variables understand go to system variables edit our system variables take the path of the gradel up to bin directory then edit system variables once we edit the system variable go to this environment variable section go to path click on edit here we don't have the gradal path now click on new I'm setting the path for the Gradle Gradle up to bin directory click on Okay click on Okay click on okay that's it so with this I'm able to set up the path for Gradle how to check the Gradle is working or not simply go to command prompt gradel iph V when I click on this gradel iph V yes gradel 7.6 version is working in my system once the gradel installation got complete we are good to go now guys in the Gradle if you want to create a project then you will use a command simple gradel init command gradel init command is used to create the project by using Gradle okay so let me go to here CMD I'm opening the command prompt now I'm executing a command called Gradle init command just observe do you want to create one application in the Gradle or do you want to create one Library by using gradel do you want to create one plugin by using gradel I want to create one application by using Gradle so choose one option when I execute this program it is saying that select type of the project to generate do you want to generate a basic application or do you want to generate one complete application do you want to generate one Library do you want to generate one plugin what is your option from one to four you select it I want to generate one application I'm giving two option two when I click on option two it is asking select implementation language which type of project you want to develop do you want to develop C++ project do you want to develop groovy project do you want to develop Java project or you want to use cotlin project or you want to use a Scala or you want to use a shift what type of project you want to develop by using Gradle H here comes the difference between Maven and Gradle Navin is used to develop only Java projects but gradel not only for Java it is supporting for C++ supporting for groovy supporting for cing supporting for Scala supporting for shift also so Gradle is universal build tool not only for Java you can use gradel for other languages also whereas Maven can be used only for Java projects Gradle can be used for Java as well as for other projects also now what type of language you want to use to create the project I want to create the Java project give the option three now when I give option three it is asking so split functionality class sub projects or do you want to create only one project or do you want to create multiple projects I want to create only one project now give option one when I give option one it is asking build script so build script is nothing but a script file which which gradel will use to perform the build process I want to tell to Gradle hey Gradle download spring jar files a gradel add the jar files to build path a Gradle compile my project source code Gradle package my project as a jar file so all these build process steps I want to give for the Gradle so that build script we need to write do you want to write the build script by using groovy or do you want to write it by using cotlin I want to write the build script by using groovy I'm giving the option as one okay when I give the option as one generate build using new apis and behaviors some Futures may change in the next minor release default option no I don't want any new changes here now which testing framework you want for Java project to perform unit testing which test framework we are going to use I will use some junit four give the option one right when I give the option one what is the project name you want do you want the project name as current directory name my current directory name is gradel Workshop do you want same thing as a project name no I will give my project name as my Gradle app one okay what is the default package name you want the default package name I want as in asoke ID finally my build is successful that means I'm able to create one project by using gradel so what is the command that I have used to create a project by using gradel gradel init command the the command that I used to create the gradel project is Gradle init command when I execute gradel init command gradel demon started it asked me B what type of project you want to generate by using Gradle which language you want to use to develop that project okay what is the build script language that you want to use in your project which testing framework you want to use in your project what is the name that you want for your project what is the package name you want in the project it is asking all the details based on the given details Gradle generated one project for us let us go here gradel generated one project for me so whenever we generate a gradel project a gradel project structure is going to look like this if you open the Gradle project in the IDE so you can see that left side screenshot like this a gradel project will look like in the IDE if you see in the gradel project what are the folders will be created the most important thing in the gradel that is build. gradel in the build. gradel we are going to write our gradel build script that means from where it has to download the dependencies what dependencies it has to download how to test those classes in the project how to compile how to package all the build related configuration we are going to write inside build. Gradle you see build. gradel file got generated here okay inside the gradel here inside the app you can see build. gradel file got generated build. gradel file contains gradel configuration so in the maven we will have a pom.xml to do the maven configuration in the gradel we have build. gradel in the maven we have pom.xml in the gradel we will have build. gradel right and one more directory is available gradel directory inside the gradel directory there is a wrapper gradel wrapper is available Gradle wrapper is very very very very useful concept sir what is this gradel wrapper what this Gradle wrapper will do Gradle wrapper will run the Gradle without installing in the another computer now I have installed Gradle in my system I created a Gradle project in my system if I give this gradel project for you without installing the gradel software you can run in your system because gradel wrapper will take care of the Gradle installation in your system so now if you go for Maven if you want to run the maven in your computer you will need to install the maven then only you can build Maven project if I want Maven to build in my project I need to install Maven then I I can build it so to execute the maven commands we need to install the maven first whereas in the Gradle that installation is not required already I have installed gradel I have created the gradel project okay so if I give this gradel project for you you can execute the gradel project you can build the gradel project in your system without installing the Gradle that is called gradel wrapper gradel wrapper will provide you the gradel runtime to build your gradel project are you guys clear with my point in one system we will install the gradel and we will create a gradel project that Gradle project we can build in any system because Gradle wrapper will take care of the runtime so to install the Gradle in your system Gradle wrapper will be used okay so in that Gradle wrapper Gradle wrapper jar file available Gradle wrapper properties available that means to run the gradel w in your system what settings are required what configurations are required those configurations will be part of gradel wrapper now gradel W so gradel w is the wrapper for Linux and Mac operating systems gradel W.B file this is the wrapper for Windows so now if I give the gradel project for you you can run that gradel project by using gradlew.bat file that is a gradel wrapper file for Windows operating system system fifth one if you want to use the Gradle project in the Linux machine you can use gradel W fourth one as a gradel wrapper to create this grad rapper files this gradel wrapper jar gradel wrapper properties files are available settings. gradel file will contain our project details build. gradel that is the most important file in the gradel build. gradel file is the one where we will write our script for example I want my SQL connector jar file for my project my SQL connector is a dependency for my project I will tell to gradel he gradel please download my SQL connector that configuration I will write in the build at gradel hey gradel I want hibernate jar file I will configure hibernate jar file in the build. gradel I want to Spring boot hey gradel download the spring boot dependency for my project and add to the build path so whatever the build process that we want to do we will inform form to the gradel by using build. gradel script file if the people are using Maven that is equal to p. XML in the maven we will have pom.xml in the gradel we have build that gradel so what is the difference between gradel and Maven if you want to do the maven build Maven software should be installed in your system but for the gradel it is not required by using Gradle wrapper we can run the gradel in any machine without installing it so that script file in the pom.xml in the maven script file is a XML configuration whereas in the gradel the script you can write by using groovy language or you can write it by using cotl so in today's session I will explain how to write that script by using groovy language it is very easy Once the Gradle project is created SRC main Java SRC test Java will be created and build. gradel file gradel W gradlew.bat settings. gradel so once this gradel is available see the app SRC main Java in Ashok it app. Java one Java class is created by default okay similarly one test class also created by default test Java in. as. app test. Java one junit test class also created by default so we asked this Gradle to create a sample Java project it created the Java project we can execute some tasks in the gradel in the maven we call it as Maven goals in the gradel there are called as gradel tasks what are the tasks we can ex task nothing but that action gradel has to perform let's go for gradel tasks when I execute a command gradel tasks it is telling what tasks we can execute on this project when I execute graded tasks what tasks we can execute it is telling that you can you can execute several tasks in this project run task so when you execute the Run task run this project as a jvm application if you execute gradel run it is going to run this application directly you can execute to build a task when you execute build it will perform the build process compile test then package application as a jar file build dependence and build needed classes clean jar test classes so build say setup init wrapper distribution tasks disc jar dist jip bundles the project as a distribution jip file or jar file Java doc generate the documentation for the project okay so these are the some tasks that are available in the gradel we can execute those tasks for example if I execute a task gradlew.bat this is my wrapper always recommended to perform gradel operations by using Gradle wrapper for Windows window what is the gradel wrapper gradlew.bat gradlew.bat is used as a wrapper for the windows so here I'm using gradlew.bat space run when I execute run command what is going to happen now you see Hello VA am I able to get the output yes I'm getting the hello VA let me change the message in my project go to app SRC main Java in Ashok it app. Java it is giving just a hello world okay let me change this message welcome to Ashok welcome to Ashok like this I'm changing the message in this Java program so now just I am saving the program who will compile this program and who will run this program do I need to compile do I need to run or it will be taken care by gradel do I need to compile do I need to run or it will be taken care by gradel do I need to compile this project or this compilation will be taken care by gradel gradel will take care that how to compile this project by using gradel simple let me execute a command called gradel w. bat it is my wrapper you can execute directly gradel also you can use the gradel command also or you can use gradel wrapper also anything is fine gradel space build when I execute gradel space build what will happen it is executing several tasks it will compile the classes it will test the classes it will package the classes okay gradel build is a success now I will execute gradel run command when I execute gradel run command you see it is giving the program output welcome to Ashok so when I execute gradel run it is compiling my program it is running my program also okay now let us see what happened in our project app build generated build generated in the ls app. jar our project is packaged as a jar file also whatever the build process is there downloading the dependencies adding the dependencies to the build path compiling the project source code executing unit test cases packaging the project as a jar file or War file who is doing these steps as a programmer I'm doing these steps are my Gradle is doing these steps build process is automated or build process is not automated I want to compile my classes okay gradel space compile Java this is one task for the gradel I'm telling to Gradle hey Gradle compile Java when I use gradel compile Java it will perform compilation of the project is going to perform compilation of the project so this is a task see here when I give gradel compile Java it is compiling my project when I execute gradel build when I execute gradel build it will compile and it is going to package my project as a jar file when I use gradel run it is running my class whatever the main class is available in the project that class also executed by gradel gradel run command is executing that main class also how to work with build script in the gradel so to work with the build script in the gradel first let's understand this is the most important part guys in the interview also they will ask this build. Gradle how we have pom.xml file in the maven in the Gradle we will have build. gradel file so in this build. gradel file we need to write the gradel scripting the configuration that is required for the gradel how we will write the mavin pom.xml similarly we need to write build. gradel file in the build. gradel file I'm using groovy DSL domain specific language domain specific language I'm going to use the first thing that we will write is plugins what plugins you want to use in the project do you want to use a Java do you want to use a spring boot what you want that you can specify as a plugin for example for this project I need Java ID Java plugins ID Java I want Java in order to run this project I need Java to run this project and the next one is dependencies section what are the dependencies you want to use in this project okay so dependencies I want to use dependency like my SQL connector I want to use dependency as a my SQL connector iPhone J okay and I want to use a dependency test implementation I want to use junit dependency for my test implementation my SQL connector dependency I need to connect with the database jdbc driver I need instead of I am downloading the driver I'm telling to the gradel to download that driver so this is a test implementation that means this junit jar file is required only for the test my SQL connector is required for the compile time as well as for run time to compile my project to run my project I need this my SQL connector junit is used only for the test compilation test execution so we will configure the plugins we will configure the dependencies and similarly here we can configure repositories also here we can configure repositories also from where you want to download the dependencies I want to download the dependencies from mavin Central repository so this MySQL connector jar file I want to download from the mavin central repository okay here you can configure mavin Central repository and here you can configure plugins that are required what are the repositories you want to use what are the dependencies you want to use you can configure here like this we are going to write our build. gradel scripting okay in the build at gradal scripting we will specify what plugins we need what repositories we need and what are the dependencies we need so I want to use a hibernated dependency I need to declare that hibernated dependency here I want to use a seret dependency I need to declare in the dependency section I want to use a spring boot I need to declare that spring boot dependency here what are the dependencies you want for your project those dependencies we need to declare in the dependencies section from where we need to get the dependencies the dependencies should be downloaded from the maven Central repository we can configure the repository section here what plugins you want to use for your project we need to configure that in the plugins section we need to configure that in the plins section okay so which version of the Java you want to use that also you can configure here Source compatibility Source compatibility is equal to 1.8 Target compatibility is equal to 1.8 that means I want to compile my project by using Java 1.8 version and I want to run my project by using Java 1.8 version maybe in my system Java 11 is available but for this project I want to use Java 1.8 Source compatibility I want to use Java 1.8 Target compatibility I want to use Java 1.8 which version of java you want to use in your project that also you can specify by using these options in the gradel script file can we create a spring boot project by using gradel how to create spring boot project by using gradel file new other boot application I want to create a spring boot project to create the spring boot project we need to select a spring starter spring starter project I'm giving zero to gradel app here guys observe if you want to create a spring starter project nothing but spring boot either gradel or Maven is mandatory you need to select either Maven as a build tool or you need to select either gradel as a build tool without using Maven and gradel you cannot create that springboard project so I'm using gradel as a build tool group ID I'm using it as in. asoke it and artifact ID zero to gradel app see how I am creating spring boot project using gradel file new other Gradle project not Gradle project spring boot project spring starter project I'm selecting the artifi project name as 02 gradel app 02 Gradle app click on next here I want to select web dependency to create the rest controller in the spring boot if you want MySQL driver you can select if you want verle driver you can select directly I'm selecting only web dependency click on next click on finish so with this my spring boot project is creating by using cradle as a build tool yeah project is created successfully you can see that spring boot application created now SRC main Java spring boot start class is created SRC resources application properties file is also created test Java is created go to build. gradel file wow see it is giving build script by default Java plugin boot plugin dependency management Source compatibility 1.8 Maven Central repository it requires spring boot web starter dependency as a implementation and spring boot starter test as the dependencies okay spring boot is coming by default now let me go to this application let me take a rest controller let me take a rest controller let me write one method just to test it is it working or not get welcome message welcome to springboard I'm giving welcome to springboard that's it I'm mapping this to get request method by using get mapping with empty URL import the package so here whatever the jars that are required for my project am I downloading these boot jar files or Gradle is downloading all these jar files guys whatever the jar files are available in the build path did I download these jar files or my Gradle tool is downloading these jar files who is downloading these jar files for us Gradle is downloading this jar files and add it to build path okay am I writing this build. gradel file or when I create the boot application this file is coming by default when I create the boot application this file is coming by default file is coming by default okay fine now can we run this project now we have a rest controller can we package this project as a jar file and can we run this project can we package this application as a jar file and can we run this project tell me how to package this project how to package this project guys which which task we need to execute which task we need to execute to package this project gradel build so I need to execute from the command prompt or I can execute from IDE also do I need to execute from command prompt I can execute from IDE also execute from ID also okay go to this zero to Gradle app project zero to grad appb project currently build folder is available in the project or build folder not available in the project guys currently my build folder is available or my build folder is not available build folder is not available okay I will compile this from I will execute this from command prom CD space z to gradel application currently I'm pointing to zero to gradel application in this application build folder not available let me execute gradel build I'm executing gradel build compile Java it is compiling my Java classes compiling my Java classes test is also completed it is doing the test now executing the unit test classes junit test classes it is executing my classes compilation is Success it is executing my junit test classes it is executing my junit test classes okay once the build is Success go to Project can you see build folder build folder available in the build folder can you see lips H can you see the jar file is created jar file is created I don't like this name this lengthy name can we short this jar file name can we customize this jar file name how to customize this jar file name go to build. gradel build. Gradle here specify jar tag I want to customize it J tag archives base name is equal to app that's it I'm giving archives base name so what is the meaning of archives base name what is the meaning of archives base name it will customize the name now let me do the clean and build again let me do the clean and build Gradle clean build Gradle clean build I'm doing there we use MAV and clean package right here gradel clean build clean build means delete the build directory and again build it delete the existing build directory and create the new output build success go to build directory now go to lips directory app snapshot. jar it created app 001 iph snapshot. jar so whatever the name I have given for that name it is giving the version also remove that version I don't want to give the version okay again do the gr clean build build success go to build directory now can you see app. jar file is created now can you see app. jar file is created how I customized that jar file name by using jar archives basement so if I tell like this it will give archives base name with that name my jar file is created so jar file is available in the build lips can we run that jar yes how to run the jar Javas space iphon jar build slash lips/ app. jar I'm running my jar file in that jar file spring boot application is available spring boot rest API is available spring boot will take care of the servers automatically we know need to set the server also spring boot will take the Tomcat server so spring boot application I have created and I package it that spring boot application as a jar file and I'm running that jar file so that spring boot application is giving the Tomcat server running on the port number 8080 go and access our application go and access our application Local Host colon 8080 that's it Local Host colon 8080 my spring boot application which is running here it will give the output welcome to spring board to run the boot application we can do one more thing also directly we can use boot run command so this my gradel application is available let me create let me execute gradel clean what gradel clean will do gradel clean deleting the build directory currently do we have the build directory or we don't have the build directory we don't have the build directory how to create the build directory Gradle build we will use a command Gradle build when I use gradel build it will compile it will package my project yes it is done build is done so my project is packaged my project is packaged build folder is created lips y jar is created okay so fine in order to do this we can simply use Gradle boot run if you use gradel boot run it is going to run the boot application so this application is executing comcat server 8080 port number application started Local Host colon 8080 yes are we able to [Music] access
Info
Channel: Ashok IT
Views: 3,811
Rating: undefined out of 5
Keywords: GradleTutorial, BuildAutomation, JavaBuildTool, AndroidDevelopment, GradleBuildScript, DependencyManagement, TaskConfiguration, PluginIntegration, BuildScripting, ProjectConfiguration, BuildAutomationTools, GradleBuildWorkflow, JavaDevelopment, AndroidStudio, SoftwareBuilds, CodeOptimization, ContinuousIntegration, SoftwareDevelopmentTools, ProgrammingTips, OpenSourceDevelopment, maven vs gradle, java build tools, learn gradle build tool, java project build process, devops tools, ashok it, java projects
Id: I84f9Q5bFBA
Channel Id: undefined
Length: 38min 56sec (2336 seconds)
Published: Sun Oct 08 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.