Command Palette

Search for a command to run...

Back to the lesson: Topic 15.4 — Maven and Gradle Basics
Core Java · Example 3 of 3 Java 9+

Gradle-style task graph with up-to-date checks

A depth-first walk gives a valid order (a topological sort, see the DSA course's graph modules). Real Gradle fingerprints file contents and outputs, not version strings.

Maven and Gradle are build tools: from one file (pom.xml or build.gradle.kts) they download your libraries and the libraries those need, compile your code, run the tests and package a JAR with one command. Maven uses a fixed lifecycle of phases and XML configuration; Gradle uses a task graph, a Kotlin or Groovy script, and skips work whose inputs haven't changed.

Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Extend the "nearest wins" program so it also prints the Gradle choice (highest version) for each artifact. Compare versions numerically, part by part.

02

Write a program that prints the Maven coordinates group:artifact:version split into their three parts, and says whether the version is a SNAPSHOT.

03

Write the Gradle dependencies { } block for: Jackson databind 2.17.2 for main code, the PostgreSQL JDBC driver 42.7.4 only at runtime, and Mockito 5.12.0 for tests.

Explain it without notes

01

What does a build tool do for a Java project?

02

Explain the Maven build lifecycle and the relationship between phases, plugins and goals.

03

How do Maven and Gradle resolve version conflicts between transitive dependencies?

04

What are dependency scopes or configurations, and why do they matter?

05

Why is Gradle often faster than Maven on large projects?

Gradle-style task graph with up-to-date checks Java 9+
Sign in to run this example in your browser.

Expected output

first build:
> Task :compileJava
> Task :processResources
> Task :classes
> Task :jar
> Task :compileTestJava
> Task :test
> Task :build
5 actionable tasks: 5 executed

only a test file changed:
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar UP-TO-DATE
> Task :compileTestJava
> Task :test
> Task :build
5 actionable tasks: 2 executed, 3 up-to-date