Every Java pipeline you will ever support starts the same way: a build tool turns source code into a tested, versioned artifact that the rest of the pipeline can ship. As a DevOps engineer you rarely write the Java, but you own the build: you make it fast, repeatable and secure, and you are the one paged when it breaks at 2 a.m. This lesson shows the problem a build tool solves by first doing the work by hand.
In simple words
- Build tool: a program that turns source code into something you can run or ship: it downloads libraries, compiles, tests and packages.
- Maven: the classic build tool for Java. Projects follow a standard layout and are described in a pom.xml file.
- Gradle / npm: Gradle is a faster, script-based Java build tool. npm is the build and package tool for JavaScript.
- Artifact: the file a build produces, such as a .jar or .war file.
The job, step by step
Turning code into something deployable is always the same chain of steps:
source code ──► compile ──► test ──► package ──► publish ──► deploy .java files .class files JUnit .jar/.war Artifactory server, container, Kubernetes- Compile: turn
.javasource into.classbytecode the JVM can run. - Resolve dependencies: download every library the code uses (and the libraries those use) at the right versions.
- Test: run the unit tests and stop if any fail.
- Package: zip the classes and resources into one artifact, usually a
.jar(or.warfor older web servers). - Publish: upload the artifact, with a version number, to a repository such as Artifactory or Nexus so other teams and later pipeline stages can use exactly that build.
A build tool does all of this from one command, the same way on every laptop and every CI runner.
Try it by hand first
The practice terminal has a small Java service, shop-api, in your home directory. Look at what is inside:
cd ~/shop-apifind src -name "*.java"src/main/java/com/acme/shop/App.javasrc/main/java/com/acme/shop/PriceCalculator.javasrc/test/java/com/acme/shop/PriceCalculatorTest.javasrc/test/java/com/acme/shop/CheckoutIT.javaPriceCalculator.java uses nothing but plain Java, so the Java compiler javac can build it on its own:
javac -d /tmp/out src/main/java/com/acme/shop/PriceCalculator.javals /tmp/out/com/acme/shopPriceCalculator.classNow compile the whole application the same way:
javac -d /tmp/out src/main/java/com/acme/shop/*.java # fails: the libraries are missingsrc/main/java/com/acme/shop/App.java:3: error: package com.fasterxml.jackson.core does not existimport com.fasterxml.jackson.core.JsonProcessingException; ^src/main/java/com/acme/shop/App.java:4: error: package com.fasterxml.jackson.databind does not existimport com.fasterxml.jackson.databind.ObjectMapper; ^src/main/java/com/acme/shop/App.java:5: error: package org.slf4j does not existimport org.slf4j.Logger; ^3 errorsApp.java uses Jackson (to write JSON) and SLF4J (for logging). Those libraries are not part of Java. To build by hand you would have to:
- Find the right Jackson and SLF4J jars and download them, plus every jar they need (Jackson databind needs jackson-core and jackson-annotations, for a start).
- Pass all of them on a long
-cpclasspath tojavac. - Compile the tests separately with JUnit and Mockito (and their dependencies) on the classpath.
- Run the tests with the JUnit launcher.
- Build a jar with the right manifest, and repeat it all on every machine, keeping versions in sync by hand.
That is fragile, slow and different on every machine. This is exactly what build tools were invented for.
The same thing with Maven
Maven reads one file, pom.xml, which lists the project's name, version and dependencies. Everything else follows conventions. One command does the whole chain:
mvn package[INFO] Scanning for projects...[INFO][INFO] -------------------------< com.acme:shop-api >--------------------------[INFO] Building shop-api 1.0.0-SNAPSHOT[INFO] from pom.xml[INFO] --------------------------------[ jar ]---------------------------------[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.18.1/jackson-databind-2.18.1.jar (1.6 MB at 9.0 MB/s)...[INFO] --- compiler:3.13.0:compile (default-compile) @ shop-api ---[INFO] Compiling 2 source files with javac [debug release 21] to target/classes...[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0...[INFO] Building jar: /home/lynuxpro/shop-api/target/shop-api-1.0.0-SNAPSHOT.jar[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------In one command Maven downloaded the libraries from Maven Central (the public repository of Java libraries), compiled the code, compiled and ran the tests, and built the jar. Everything it produces goes in one folder, target/:
ls targetjava -jar target/shop-api-1.0.0-SNAPSHOT.jarclasses jacoco.exec original-shop-api-1.0.0-SNAPSHOT.jar shop-api-1.0.0-SNAPSHOT.jar surefire-reports test-classes14:31:07.412 [main] INFO com.acme.shop.App -- Starting shop-apiOrder total: 99{"orderId":42,"total":99}Run mvn package a second time and notice how much quicker it is: the libraries are already cached in ~/.m2/repository, and the compiler sees nothing has changed.
Why this matters to DevOps
| Without a build tool | With a build tool |
|---|---|
| "Works on my machine" | Same result on every laptop and runner |
| Library versions copied around by hand | Versions declared once in pom.xml |
| Someone forgets to run the tests | Tests run on every build, failures stop it |
Artifacts named app-final2.jar | Versioned artifacts like shop-api-1.4.2.jar |
| No idea which libraries are inside | A full dependency tree you can scan for CVEs |
Your responsibilities around the build usually include:
- CI pipelines that call the build tool (
mvn verify,mvn deploy). - Caching the dependency cache so pipelines don't download the internet every run.
- Artifact repositories (Artifactory, Nexus) and the credentials to publish to them.
- Security: scanning dependencies, generating an SBOM, pinning versions.
- Speed: parallel builds, build caches, only building what changed.
Maven, Gradle and npm
Three build tools cover most of what you will meet:
| Tool | Ecosystem | Build file | Style |
|---|---|---|---|
| Maven | Java, Kotlin | pom.xml (XML) | Convention over configuration, fixed lifecycle |
| Gradle | Java, Kotlin, Android | build.gradle.kts (code) | Flexible task graph, incremental and cached |
| npm | JavaScript, TypeScript | package.json | Scripts plus a dependency lock file |
They share the same ideas, so learning one deeply makes the others easy: declare dependencies, resolve them from a repository, run a standard set of steps, produce a versioned artifact. This course goes deep on Maven (still the most common build tool in enterprise Java) and covers Gradle and npm in lesson 13.
Where the build sits in a pipeline
The shop-api project already has a GitLab pipeline. Look at it:
cat .gitlab-ci.ymlimage: maven:3.9-eclipse-temurin-21 variables: MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository" MAVEN_CLI_OPTS: "--batch-mode --errors --no-transfer-progress -s ci/settings.xml" cache: key: maven-$CI_COMMIT_REF_SLUG paths: - .m2/repository stages: [build, test, publish] build: stage: build script: - mvn $MAVEN_CLI_OPTS -DskipTests package...Every line here is a decision about the build: which Java image, where the dependency cache lives, which settings file holds the Artifactory credentials, and which Maven command runs in which stage. By the end of this course you will understand and be able to tune every one of them.
Key points
- A build tool compiles, resolves dependencies, tests, packages and publishes from one command.
- Doing it by hand fails as soon as the code uses a library: you would have to find and wire every jar yourself.
- Maven's single source of truth is
pom.xml; its output goes intarget/; downloaded libraries are cached in~/.m2/repository. - DevOps owns the build's speed, caching, repositories, credentials and security.
- Maven, Gradle and npm follow the same ideas with different file formats.