πŸš€ 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.