Introduction to Gradle - Beginners Guide



Introduction to Gradle - Beginners Guide



Introduction to Gradle

Gradle is an open-source build automation system that builds upon the concepts of Apache Ant and Apache Maven. Gradle has a proper programming language instead of an XML configuration file and the language is called ‘Groovy’.

Gradle uses a directed acyclic graph ("DAG") to determine the order in which tasks can be run.

Gradle was designed for multi-project builds, which can grow to be quite large. It supports incremental builds by intelligently determining which parts of the build tree are up to date, any task dependent only on those parts does not need to be re-executed.


Advantages of Gradle

Gradle provides many advantages:

Declarative Builds: Probably one of the biggest advantages of Gradle is Groovy language. Gradle provides declarative language elements. Which provide a build-by convention support for Java, Groovy, Web, and Scala.

Structured Build: Gradle allows developers to apply common design principles to their build. It provides a perfect structure for the build, so that well-structured and easily maintained, comprehensible build structures can be built.




Deep API: Using this API, developers can monitor and customize its configuration and execution behaviors.

Scalability: Gradle can easily increase productivity, from simple and single the project builds to huge enterprise multi-project builds.

Multi-project builds: Gradle supports multi-project builds and also partial builds.

Build management: Gradle supports different strategies to manage project
dependencies.

First, build integration tool − Gradle completely supports ANT tasks, Maven and lvy repository infrastructure for publishing and retrieving dependencies. It also provides a converter for turning a Maven pom.xml to the Gradle script.

Ease of migration: Gradle can easily adapt to any project structure.

Gradle Wrapper: Gradle Wrapper allows developers to execute Gradle builds on machines where Gradle is not installed. This is useful for the continuous integration of servers.

Free open source − Gradle is an open-source project and licensed under the Apache Software License (ASL).

Groovy: Gradle's build scripts are written in Groovy, not XML. But unlike other approaches, this is not for simply exposing the raw scripting power of a dynamic language. The whole design of Gradle is oriented towards being used as a language, not as a rigid framework.

Gradle Build Scripts

Gradle builds a script file for handling projects and tasks. Every Gradle build represents one or more projects.
A project represents a library JAR or a web application.

Gradle Wrapper

The wrapper is a batch script on Windows and a shell script for other operating systems. Gradle Wrapper is the preferred way of starting a Gradle build.
When a Gradle build is started via the wrapper, Gradle will automatically download and run the build.




Gradle Build Life Cycle

Gradle Build life cycle consists of the following three steps:

-Initialization phase: In this phase the project layer or objects are organized.

-Configuration phase: In this phase all the tasks are available for the current build and a dependency graph are created.

-Execution phase: In this phase tasks are executed.


Gradle Build Task

Gradle Build Tasks is made up of one or more projects and the project represents what is been done with Gradle.

Some key features of Gradle Build Tasks are:

1. Task has life cycled methods [do first, do last]
2. Build Scripts are code
3. Default tasks like run, clean, etc
4. Task dependencies can be defined using properties like dependsOn

Gradle Dependency Configuration

Dependency configuration comprises of the external dependency, which you need to install well and make sure the downloading is done from the web.

There are some key features of this configuration which are:

1.   Compilation: The project which you would be starting and working on the first needs to be well compiled and ensure that it is maintained in the good condition.



2.   Runtime: It is the desired time which is required to get the work dependency in the form of collection.

3.   Test Compile: The dependencies check source requires the collection to be made for running the project.

4.   Test runtime: This is the final process which needs the checking to be done for running the test that is in a default manner considered to be the mode of runtime


Gradle Daemon

A daemon is a computer program that runs as a background process, rather
than being under the direct control of an interactive user.

Gradle runs on the Java Virtual Machine (JVM) and uses several supporting
libraries that require a non-trivial initialization time.

As a result, it can sometimes seem a little slow to start. The solution to this
problem is the Gradle Daemon: a long-lived background process that
executes your builds much more quickly than would otherwise be the case.
We accomplish this by avoiding the expensive bootstrapping process as
well as leveraging caching, by keeping data about your project in memory.

Benefits Of Daemon in Gradle:

1. It has good UX
2. It is very powerful
3. It is aware of the resource
4. It is well integrated with the Gradle Build scans
5. It has been default enabled





SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post