Java Builds: What Maven & Gradle Do
A Java program of three classes can be built with one javac command. A real service is different: forty modules, two hundred third-party JARs that depend on each other, tests that must run before anything ships, a fat JAR for production, a library published for other teams, and a CI server that should rebuild only what changed. Nobody types that by hand. On the JVM, two tools do it for almost everyone: Apache Maven and Gradle.
This course teaches both, side by side, the way a build engineer uses them.
Who this course is for
You can write Java: packages, classes, interfaces, main, a unit test. The Java course covers that (its lesson Java Packages explains the package-to-folder rule every build tool relies on). Gradle build scripts are written in Kotlin, so the Kotlin course helps, though you'll only need lambdas and property syntax. The language-neutral ideas (build graphs, incremental builds, semantic versions, diamond dependencies, caching) are in Build Fundamentals; you'll recognise them here.
What a JVM build tool does
| Job | Maven | Gradle |
|---|---|---|
| Describe the project | pom.xml, declarative XML |
build.gradle.kts, a Kotlin script |
| Resolve dependencies | from Maven repositories, nearest declaration wins | from the same repositories, highest version wins |
| Order the work | a fixed lifecycle of phases | a task graph computed for each build |
| Compile, test, package | plugins bound to phases (compiler, surefire, jar) | tasks added by plugins (compileJava, test, jar) |
| Skip unchanged work | little: mostly recompile checks | up-to-date checks, a build cache, a configuration cache |
| Ship | install, deploy to a repository |
maven-publish to the same repositories |
Both tools use the same repository format (the "Maven repository layout") and the same coordinates (groupId:artifactId:version). A library built with Gradle is consumed by Maven builds every day, and the other way round. You'll do exactly that in this course.
One project, two builds
Both tools also agree on a folder convention: production code in src/main/java, tests in src/test/java. So the same source tree can carry a pom.xml and a build.gradle.kts. Here is a minimal project built by both:
mkdir -p hello/src/main/java/demo && cd hello
cat > src/main/java/demo/Hello.java <<'SRC'
package demo;
public class Hello {
public static void main(String[] args) {
System.out.println("Hello from " + System.getProperty("java.version"));
}
}
SRC
cat > pom.xml <<'POM'
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>hello</artifactId>
<version>1.0.0</version>
<properties>
<maven.compiler.release>21</maven.compiler.release>
</properties>
</project>
POM
cat > settings.gradle.kts <<'KTS'
rootProject.name = "hello"
KTS
cat > build.gradle.kts <<'KTS'
plugins { java }
version = "1.0.0"
KTS
mvn -q package
gradle -q build
ls target/*.jar build/libs/*.jar
java -cp target/classes demo.Hello
java -cp build/libs/hello-1.0.0.jar demo.Hellobuild/libs/hello-1.0.0.jar
target/hello-1.0.0.jar
Hello from 21.0.13
Hello from 21.0.13
-q (quiet) hides everything but errors, so the session shows only the results: Maven wrote target/hello-1.0.0.jar, Gradle wrote build/libs/hello-1.0.0.jar, and both contain the same compiled class. The default output of each tool is much richer, and reading it is a skill this course teaches.
How the sessions in this course work
Every bash run block is a real terminal session, recorded on Linux with:
| Tool | Version |
|---|---|
| JDK | Eclipse Temurin 21.0.13 (LTS) |
| Maven | 3.9.16, Maven Wrapper 3.3.4 |
| Gradle | 9.8.2 (Kotlin DSL with Gradle's embedded Kotlin) |
The recording machine has no network. Its local Maven repository (~/.m2/repository) and Gradle cache (~/.gradle/caches) were filled in advance with a fixed set of real artifacts: the standard Maven plugins, JUnit Jupiter 5.14.4 and 6.1.3, AssertJ, Guava, Apache Commons Lang, the Jackson 2.22.4 BOM and SLF4J. Asking for a version that isn't there fails, exactly as it would behind a strict corporate proxy. A writable folder, /srv/maven-repo, plays the part of your company's artifact repository (Nexus, Artifactory, GitHub Packages): you'll deploy and publish to it.
java -version 2>&1 | head -1
mvn -v | head -1
gradle -v | grep '^Gradle'
ls ~/.m2/repository/org/apache/maven/plugins | head -5openjdk version "21.0.13" 2026-10-20 LTS
Apache Maven 3.9.16 (2bdd9fddda4b155ebf8000e807eb73fd829a51d5)
Gradle 9.8.2
maven-antrun-plugin
maven-archetype-plugin
maven-assembly-plugin
maven-clean-plugin
maven-compiler-plugin
Timings such as Total time: 1.2 s or BUILD SUCCESSFUL in 3s will differ on your machine. Gradle's first command in a session also starts a background daemon (a long-lived JVM that later builds reuse); its start-up message is left out of the recorded output.
The course map
- By hand:
javac, the classpath andjar, so you know what the tools automate. - Maven: the POM, the lifecycle, plugins and executions, dependency scopes and mediation, BOMs, testing, shade, enforcer, multi-module reactors, profiles,
settings.xml, mirrors,install/deployand the wrapper. - Gradle: the task graph, the Kotlin DSL, the Java plugins, multi-project builds, configurations, version catalogs, convention plugins, lazy configuration, incremental builds, the build cache, the configuration cache, JaCoCo,
maven-publishand the wrapper. - Comparison and migration: when to choose which, and moving a Maven build to Gradle.
- Toolkit, field notes, exercises and a mini project: one multi-module app built with both tools, its library published to
/srv/maven-repoand consumed from there.
Android builds use Gradle too, through the Android Gradle Plugin; that is the subject of Mobile Build Pipelines, which builds on this course.
Test yourself
What do Maven and Gradle share, which lets a Gradle-built library be used by a Maven project?
- The same build script language
- The repository layout and groupId:artifactId:version coordinates
- The same lifecycle phases
- Nothing; they need a converter
Where do Maven and Gradle put the JAR of a project by default?
- Both in
out/ - Maven in
target/, Gradle inbuild/libs/ - Maven in
build/, Gradle intarget/ - Both in
dist/
How does Gradle decide the order of work in a build?
- A fixed list of phases
- It computes a task graph from task dependencies for the tasks you requested
- Alphabetically by task name
- In the order tasks appear in the script