Skip to content
Latchkey

mvn Command: Build Maven Projects in CI

mvn builds, tests, and packages Java projects through Maven lifecycle phases.

Maven (the mvn command) builds JVM projects through standardized lifecycle phases driven by a pom.xml. In CI it resolves dependencies from repositories, compiles, tests, and packages artifacts, with a few flags that make runs non-interactive and reproducible.

Common flags

  • clean install / verify / package - common lifecycle phase chains
  • -B / --batch-mode - non-interactive output (CI-friendly logs)
  • -DskipTests - compile tests but skip running them (-Dmaven.test.skip skips both)
  • -P profile - activate a build profile
  • -pl module -am - build a module and the ones it depends on
  • -o / --offline - run without network access
  • -s settings.xml - use a specific settings file (CI mirrors/auth)

Example in CI

Run a non-interactive verify build using a CI settings file:

shell
mvn -B -s .ci/settings.xml clean verify

Common errors in CI

  • Could not resolve dependencies for project ... - missing artifact or repo/auth issue
  • Non-resolvable parent POM - parent not found in any configured repository
  • Failed to execute goal ... compile - compilation error (see output)
  • There are test failures - surefire report lists the failed tests

Key takeaways

  • Always pass -B in CI for clean, non-interactive logs.
  • -DskipTests keeps test compilation but skips execution; -Dmaven.test.skip skips both.
  • Cache ~/.m2/repository to avoid re-downloading dependencies each run.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →