0% found this document useful (0 votes)
31 views16 pages

GRADLE

Uploaded by

anileetcode06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views16 pages

GRADLE

Uploaded by

anileetcode06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Introduction to

Gradle

UNIT II
Gradle Basics

• Gradle automates building,


testing, and deployment of
software from information
in build scripts.
Settings.gradle
• The settings file is a script file.
• It is either a settings.gradle file written
in Groovy or a settings.gradle.kts file
in Kotlin.
• The Groovy DSL and the Kotlin DSL
are the only accepted languages for
Gradle scripts.
• The settings file is typically found in
the root directory of the project.
build.gradle

• The build script is either a


build.gradle file written in
Groovy or a build.gradle.kts
file in Kotlin.
Dependency Management

• Dependency management is an automated technique for declaring and


resolving external resources required by a project.
• Gradle build scripts define the process to build projects that may require
external dependencies.
• Dependencies refer to JARs, plugins, libraries, or source code that
support building your project.
Version Catalog
• Version catalogs provide a way to centralize your dependency
declarations in a libs.versions.toml file.
• The catalog makes sharing dependencies and version configurations
between subprojects.

The version catalog typically contains four sections:


• [versions] to declare the version numbers that plugins and libraries will
reference.
• [libraries] to define the libraries used in the build files.
• [plugins] to define plugins.
Version Catalog
Declaring Dependencies

• To add a dependency to your


project, specify a dependency
in the dependencies block of
your build.gradle file.
Gradle Plugins
• Plugins can be applied to a Gradle build script to add new tasks,
configurations, or other build-related capabilities.

• Core plugins - Gradle develops and maintains a set of Core Plugins.


Ex: JavaPlugin (core plugin)
• Community plugins - Gradle’s community shares plugins via the Gradle
Plugin Portal to provide additional functionalities.
• The Spring Boot Gradle plugin packages executable JAR or WAR archives, and runs Spring Boot Java
applications.

• Local plugins - Gradle enables users to create custom plugins using APIs.
• Custom or local plugins are developed and used within a specific project or organization.
Incremental Builds & Cache

• An incremental build is a build that avoids running tasks whose inputs


have not changed since the previous build. Re-executing such tasks is
unnecessary if they would only re-produce the same output.

• The build cache stores previous build results and restores them when
needed. It prevents the redundant work and cost of executing
time-consuming and expensive processes.
Gradle in Eclipse IDE

• Install connect:
• Help -> market place -> search for “buildship gradle” -> install

• Configure:
• Windows -> preference -> gradle -> location installation directiory -> “path
of gradle”
• Apply and close
Running Gradle commands in windows
shell/ Git Bash (Linux Shell)
• Change path : cd “path”
• Gradle make dir: mkdir “Project Folder Name”
• Locate and change directory (cd) to project folder
Running Gradle commands in windows
shell/ Git Bash (Linux Shell)
• gradle init : command to initialize a new Gradle project with a
basic directory structure and default files

• Edit: vi editor, nano editor


• Vi build.gradle
• Edit :
• apply plugin: ‘java’
• apply plugin: ‘application’
• “esc” -> :wq to save and quit
• Verify edit:
• Cat build.gradle
Running Gradle commands in windows
shell/ Git Bash (Linux Shell)
• Build: gradle build
• Run: gradle run
• Test: gradle test
• gradle tasks: Lists all the available tasks in the project, including
custom tasks and built-in tasks.
Running Gradle commands in windows
shell/ Git Bash (Linux Shell)
• Check build details
• Gradle tasks
• For clean build
• gradle clean: Cleans the build directory.
• Gradle clean
• Gradle clean build
• Gradle clean build --info

You might also like