---
title: "Maven commands for build servers and CI pipelines · CloudSat"
description: "Run Maven on a CI runner or build server: pin it with the wrapper, use unattended flags, inspect dependencies, deploy safely and prepare for Maven 3.10."
url: https://cloudsat.io/learn/maven-commands-for-ci-and-build-servers
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[DevOps](https://cloudsat.io/learn/topic/devops-and-automation)

# Maven commands for build servers and CI pipelines

Run Maven on a CI runner or build server: pin it with the wrapper, use unattended flags, inspect dependencies, deploy safely and prepare for Maven 3.10.

CloudSat team November 18, 2026 7 min read

On a laptop, Maven runs when you feel like it. On a build server it runs unattended, many times a day, from a clean checkout, and every surprise turns a pipeline red. This guide covers what makes Maven predictable there: which version to run in November 2026, how to pin it, the flags for unattended builds, dependency inspection, deployment credentials, and the changes in Maven 3.10 that can break a build that passed yesterday.

## Which Maven to run in November 2026

| Line | Latest | Status | Java needed to run it |
| --- | --- | --- | --- |
| 3.10 | 3.10.1 (November 11, 2026) | Recommended for all users | 8 or newer |
| 3.9 | 3.9.16 | Still maintained, upgrade encouraged | 8 or newer |
| 4.0 | 4.0.0-rc-7 | Release candidate, not for production | 17 or newer |

The JDK that runs Maven and the Java version you compile for are separate questions: toolchains let Maven run on one JDK and build for another. On most build servers a single current LTS JDK covers both, for example `sudo apt install openjdk-21-jdk-headless` on Ubuntu or Debian. Skip the distribution's `maven` package; it often lags behind, and the wrapper below makes it unnecessary.

## Pin the version with the Maven Wrapper

A build server should not care which Maven is installed globally. The Maven Wrapper (currently 3.3.4) adds a small script to the repository that downloads the exact Maven version the project asks for, so laptops and runners build with the same tool.

```bash
# once, on any machine that already has Maven
mvn wrapper:wrapper -Dmaven=3.10.1
git add mvnw mvnw.cmd .mvn/wrapper/maven-wrapper.properties
git commit -m "Pin Maven 3.10.1 with the wrapper"
```

The default `only-script` type adds no JAR to the repository: the script fetches Maven with curl or wget, or PowerShell on Windows. To make that download tamper-evident, add the distribution's SHA-256 checksum to `maven-wrapper.properties` as `distributionSha256Sum`, in lowercase hex. From then on, pipelines call `./mvnw` instead of `mvn`, and the runner only needs a JDK.

## Pick the phase that proves enough

Maven runs a lifecycle, and asking for a phase runs every phase before it. Choosing the last phase is the main decision in a pipeline.

| Phase | What it adds | Use it in CI when |
| --- | --- | --- |
| `compile` | Main sources compiled | You only want a quick compile check |
| `test` | Unit tests through Surefire | Fast feedback on every push |
| `package` | JAR, WAR or other artifact in `target/` | You need the file, not the integration tests |
| `verify` | Integration tests and checks bound to it | The default for pull requests |
| `install` | Copies artifacts into the local repository | A later job on the same machine consumes them |
| `deploy` | Uploads artifacts to a remote repository | Publishing snapshots or releases |

`mvn clean install` is a laptop habit. In CI, `verify` proves the same thing without writing into the local repository, where a half-finished snapshot can leak into the next job on that runner.

## Flags for unattended builds

A sensible default command for a pull request:

```bash
./mvnw -B -ntp -T 1C clean verify
```

- `-B` (`--batch-mode`) never waits for input.
- `-ntp` (`--no-transfer-progress`) drops the download progress lines that bloat CI logs.
- `-T 1C` builds independent modules in parallel, one thread per CPU core. Maven warns when a plugin is not marked thread-safe.
- `-e` and `-X` add stack traces and debug output when a failure needs explaining.
- `-o` works offline from the local repository; `-U` forces a check for updated snapshots and missing releases.

In multi-module projects, build only what changed and what it needs:

```bash
# one module plus the modules it depends on
./mvnw -B -pl services/billing -am verify
# a module plus everything that depends on it
./mvnw -B -pl libs/money -amd verify
# resume a failed reactor build from one module
./mvnw -B -rf :billing verify
```

Tests have two different off switches. `-DskipTests` compiles the tests but does not run them. `-Dmaven.test.skip=true` skips compiling them too, which breaks modules that consume another module's test JAR. To run a single test method, pass `-Dtest=InvoiceServiceTest#rounding`.

Flags that every build needs belong in `.mvn/maven.config`, one argument per line, so local and CI builds behave alike. JVM options such as the heap size go in `.mvn/jvm.config` or the `MAVEN_OPTS` variable. A minimal `maven.config`:

```text
-ntp
--fail-at-end
```

## Inspect dependencies before you blame the build

Most "it compiled yesterday" failures are dependency changes. Four commands explain them:

```bash
./mvnw dependency:tree -Dincludes=com.fasterxml.jackson.core
./mvnw dependency:analyze
./mvnw versions:display-dependency-updates
./mvnw help:effective-pom -Doutput=effective-pom.xml
```

`dependency:tree` with `-Dincludes` shows which path pulls a library in. `dependency:analyze` lists dependencies you use without declaring and ones you declare without using. `versions:display-dependency-updates` (and its sibling `display-plugin-updates`) lists newer versions. `help:effective-pom` writes the POM after parents, profiles and defaults are applied, which is the fastest way to find where a setting comes from.

Maven 3.10 changed classpath ordering from depth-first to breadth-first. If two JARs carry the same class, a different one can now win. The proper fix is an explicit entry in `<dependencyManagement>`; `-Daether.system.dependencyVisitor=preOrder` restores the old order while you find the culprit.

## Cache the local repository, not the target folder

Downloading the same dependencies on every run is the slowest part of many pipelines. Cache `~/.m2/repository` between runs, keyed on a hash of every `pom.xml`, and leave `target/` out so each build compiles from a clean state. When several jobs share one runner, give each its own repository with `-Dmaven.repo.local=$PWD/.m2/repository` so concurrent builds never write the same files. If that cache lives on another volume and Maven 3.10 logs an `Invalid cross-device link` warning during install, add `-Daether.installer.hardLink=false`.

For container images, `./mvnw dependency:go-offline` in an early layer downloads most dependencies once, so code changes do not invalidate them.

## Publish artifacts without leaking credentials

The POM says where artifacts go; the settings file says who may upload. Keep tokens in the CI system's secret store and let Maven read them from the environment:

```xml
<!-- pom.xml -->
<distributionManagement>
  <repository>
    <id>internal-releases</id>
    <url>https://repo.example.com/releases</url>
  </repository>
  <snapshotRepository>
    <id>internal-snapshots</id>
    <url>https://repo.example.com/snapshots</url>
  </snapshotRepository>
</distributionManagement>
```

```xml
<!-- ci-settings.xml, committed without secrets -->
<settings>
  <servers>
    <server>
      <id>internal-releases</id>
      <username>${env.REPO_USER}</username>
      <password>${env.REPO_TOKEN}</password>
    </server>
  </servers>
</settings>
```

```bash
./mvnw -B -ntp -s ci-settings.xml deploy
```

Maven 3.10 scopes credentials: a `<server>` entry is only offered to repositories and mirrors that Maven can associate with its id, and ids must match exactly. If uploads fail with a 401 after the upgrade, compare the ids in the POM and the settings file first. When one token serves several ids, the server entry can list `<aliases>`.

## Before you move a pipeline to Maven 3.10

3.10 keeps the command line familiar but changes defaults underneath:

- **Stricter POM validation.** Many warnings from the 3.9 line now fail the build, including duplicate dependency or plugin entries, and the parent `relativePath` is checked. `-Dmaven.resolver.validation=mild` or `off` is a temporary escape hatch, not a fix.
- **UTF-8 by default** for `project.build.sourceEncoding` and `project.reporting.outputEncoding`.
- **Reproducible builds on by default**, with a fixed timestamp for archive entries. If anything reads build times from JAR entries, set `project.build.outputTimestamp` yourself.
- **No plugin management in the super POM** and no old `release-profile`: declare the plugin versions you rely on in your own POM.
- **Toolchain errors fail the build** instead of falling back to the JDK that runs Maven.

Test the move on a branch: change the version in the wrapper, run the whole pipeline and read the end of the log, where 3.10 reports plugins that use unsupported APIs. If jobs queue behind busy shared runners, a self-hosted runner on a [High Frequency VPS](https://cloudsat.io/high-frequency-vps) gives compilation fast cores and bills by the hour.

## FAQ

### Should we move to Maven 4 now?

Not for production pipelines. 4.0.0-rc-7 is a release candidate, and the Maven project says 4.x is not yet safe for production use. Maven 3.10 already shares Maven 4's resolver generation and accepts the optional profile syntax (`-P '?release-checks'`, which skips a missing profile instead of failing), so 3.10 is the useful step today.

### Is `mvn install` ever needed in CI?

Only when a later step on the same machine consumes artifacts outside the reactor, such as a separate job that builds a container from a module's JAR. Within one multi-module build, the reactor already passes artifacts between modules, so `verify` is enough.

### Why does a build pass locally and fail on the server?

Usually a different Maven or JDK, a stale local repository, or a snapshot that changed upstream. The wrapper removes the first cause, `./mvnw -v` at the top of the log shows the second, and `-U` or a fresh cache settles the third.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in DevOps](https://cloudsat.io/learn/topic/devops-and-automation)

- [Install Python on a Linux or Windows server](https://cloudsat.io/learn/install-python-on-linux-and-windows-servers): DevOps Install Python on a Linux or Windows server 7 min read
- [Jira Data Center end of life: where self-hosted teams go](https://cloudsat.io/learn/jira-data-center-end-of-life-alternatives): Self-hosting Jira Data Center end of life: where self-hosted teams go 7 min read
- [Move off GitHub without breaking builds, links or history](https://cloudsat.io/learn/move-repositories-off-github): DevOps Move off GitHub without breaking builds, links or history 6 min read
- [Switch from Terraform to OpenTofu: what changes, what breaks](https://cloudsat.io/learn/switch-from-terraform-to-opentofu): DevOps Switch from Terraform to OpenTofu: what changes, what breaks 7 min read
