Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Java builds (Maven, Gradle, JAR, WAR)

What is Gradle and how is it different from Maven?

BeginnerConceptJava builds (Maven, Gradle, JAR, WAR)
Answer

Short answer

Gradle is another build tool for Java (and Kotlin and Android). Like Maven, it downloads dependencies, compiles, tests and packages. The difference: Gradle uses a script (build.gradle, written in Groovy or Kotlin) instead of XML, and it's usually faster thanks to incremental builds and caching.

Comparison

Maven Gradle
Config file pom.xml (XML) build.gradle or build.gradle.kts (code)
Build command mvn clean package ./gradlew clean build
Output folder target/ build/libs/
Speed Good Usually faster (incremental builds, build cache)
Flexibility Fixed lifecycle, very predictable Very flexible, custom tasks are easy
Common in Enterprise Java, Spring Boot Android, large multi-module projects, Spring Boot

Example — the same dependencies in Gradle

// build.gradle
plugins {
    id 'java'
    id 'org.springframework.boot' version '3.3.4'
}
group = 'com.devopsshack'
version = '1.0.0'

repositories { mavenCentral() }

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'com.mysql:mysql-connector-j'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
./gradlew clean build          # compile + test + package
ls build/libs/                 # orders-service-1.0.0.jar
java -jar build/libs/orders-service-1.0.0.jar

What is the Gradle wrapper (./gradlew)?

The wrapper is a small script committed to the repo. When you run ./gradlew, it downloads the exact Gradle version the project expects. So every developer and every CI runner uses the same version — no "works on my machine" problems. Always use ./gradlew in pipelines, not a system-installed gradle.

What to say in the interview

"Gradle is a build tool like Maven, but its build files are scripts in Groovy or Kotlin instead of XML, and it's generally faster because of incremental builds and caching. We run ./gradlew clean build, and the JAR lands in build/libs. In CI we always use the Gradle wrapper so the Gradle version is pinned by the project, and we cache ~/.gradle between runs."

Follow-up questions you may get

  • Can Gradle use Maven repositories and Nexus? Yes — mavenCentral() or a custom maven { url ... } block with credentials.
  • What does build do in Gradle? It runs assemble (compile and package) and check (tests and verifications).
All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Java apps: Maven, Gradle, JAR & WAR

More on Java builds (Maven, Gradle, JAR, WAR)