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

What are Gradle tasks and what is the difference between build.gradle and settings.gradle?

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

Short answer

In Gradle, every unit of work is a task — compileJava, test, jar, build. Tasks depend on each other, and Gradle runs only what's needed. build.gradle configures one project (plugins, dependencies, tasks); settings.gradle defines the project name and which sub-projects belong to a multi-project build.

Example

// settings.gradle
rootProject.name = 'shop'
include 'orders', 'payments', 'common'
// orders/build.gradle
plugins { id 'java'; id 'org.springframework.boot' version '3.3.0' }
dependencies {
  implementation project(':common')
  implementation 'org.springframework.boot:spring-boot-starter-web'
  testImplementation 'org.junit.jupiter:junit-jupiter'
}

Useful commands

./gradlew tasks                 # list available tasks
./gradlew build                 # compile, test, assemble
./gradlew :orders:bootJar       # one task in one sub-project
./gradlew build --scan          # detailed build report
./gradlew build --build-cache   # reuse outputs from earlier builds

Dependency configurations (Gradle's "scopes")

implementation (compile + runtime), compileOnly (like Maven provided), runtimeOnly, testImplementation.

What to say in the interview

"Gradle models work as tasks with dependencies and only re-runs tasks whose inputs changed, which makes it fast. settings.gradle defines the multi-project structure; each build.gradle configures plugins and dependencies. Output goes to build/libs."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Java apps: Maven, Gradle, JAR & WAR

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