π How to Use Gradle: Simple Guide for Beginners
Gradle is a powerful build automation tool used for Java, Kotlin, and Android projects β and even beyond. It helps you automate tasks like compiling code, managing dependencies, testing, and packaging applications.
π§± What is Gradle?
Gradle is both flexible and fast. Itβs based on Groovy or Kotlin DSL, and unlike Maven, it doesnβt force you to follow strict XML-based structures.
You can think of it as a tool that builds, tests, and deploys your code with minimal configuration.
βοΈ Installing Gradle
Option 1: Via SDKMAN
sdk install gradle
Option 2: Via Package Manager (Ubuntu example)
sudo apt update
sudo apt install gradle
Option 3: Check Installation
gradle -v
π§© Example Project Structure
my-app/
βββ build.gradle
βββ settings.gradle
βββ src/
βββ main/java/
βββ test/java/
π‘ Basic Commands Build the project
gradle build
Run tests
gradle test
Clean build output
gradle clean
Run custom task
gradle myTask
πͺ Example build.gradle
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.apache.commons:commons-lang3:3.14.0'
testImplementation 'junit:junit:4.13.2'
}
Run:
gradle build
π§ Why DevOps Engineers Love Gradle
- Fast incremental builds
- Easy CI/CD integration
- Flexible scripting
- Works well with Docker, Jenkins, and Kubernetes pipelines
Gradle is a perfect fit if you want automation + control in one tool.