Posts

Showing posts from May, 2024

Creating and Executing a Gradle Project

Image
 Creating and Executing a Gradle Project To Create a Gradle Project: Navigate to the required directory >> Open Command prompt >> Run "gradle init" command Next it will ask for the type of build to generate: 1. Application 2. Library 3. Gradle plugin 4. Basic Next it will ask to select Implementation language: 1. Java 2. Kotlin 3. Groovy 4. Scala 5. C++ 6. Swift Next, it will ask for Target java version Next, Select Application structure: 1. Single Application Project 2. Application and Library Project Select Build Script DSL: 1. Kotlin 2. Groovy >> Select Groovy here Select Test Framework: 1. JUnit 2. TestNG 3. Spock 4. JUnit Jupiter A Gradle project containing following files will be created: Executing/Building a Gradle Project The Gradle Build process Compiles, Tests and Packages a project into a deployable unit that can be run in the target environment Gradle expects Java code to be present in src/main/java folder and tests in src/test/java project After

Why do we need a build tool?

Image
Why we need build tool? Consider this scenario where you want to run a java application   You can use java compiler (javac) provided by JDK to compile java code into Byte Code which can then run on any Machine To compile Java Programs using javac you will have to list all java source files to run the entire application Ex., "javac Program1.java Program2.java Program3.java Program4.java" This is a very tedious job. Doing this manually is a pain since there are hundreds of libraries used even in the simplest of Java Application Also one has to add Compilation classpath to make the code work. For example if the code uses libraries like testNG, Selenium etc. You need to add it to Compilation Classpath using following code: "javac -cp testNG.jar; webdriver.jar; lib3.jar" MyProgram.java In conclusion, Compiling java code manually becomes very tedious and complex task Enter Third party build tools like Spring boot, apache-comm

Groovy essentials for Gradle

  Groovy Essentials:          Groovy is a scripting language. So, you can write code outside of a class and execute it.          Gradle configuration files are written in groovy          Groovy runs on JVM          It is dynamically typed hence we can use the ‘def’ keyword while initializing a variable           Ex., def myVar = ‘Executing a script’          Semi-colons at the end of a line are not required         Brackets are optional while passing parameters to a function           Ex., def multiply (int x, int y){                println x*y           }           multiply 3,2   //This calls the multiply method. Notice no braces   required  

Gradle Fundamentals

Image
Fundamentals of Gradle: Gradle helps compiling, Testing and Packaging your application with just one command How Does Gradle know how to build your application? On a high level, You will have to describe: What type of application you are trying to build - Example- Java Libraries your application depends on i.e. it's Dependencies Any other Configuration specific to application such as Special Compile or Testing options In Gradle you provide all this information in the Build Script file i.e. the build.gradle file Project : Project is a container for everything that gradle knows about your application Each Gradle Project contains a build script (build script), gradle wrappers, .gitignore file and settings.gradle file Build Scripts: Contains tasks Tasks:  The build.gradle file contains number of tasks each with a specific job to do Eg., Task 1 to Compile, Task2 to Test and Task3 to Package your java classes into jar file Plugins: When