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.skipskips 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 verifyCommon 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
-Bin CI for clean, non-interactive logs. -DskipTestskeeps test compilation but skips execution;-Dmaven.test.skipskips both.- Cache
~/.m2/repositoryto avoid re-downloading dependencies each run.
Related guides
gradle Command: Build JVM Projects in CIgradle is the JVM build tool. Reference for build, test, --no-daemon, --build-cache, -x, --stacktrace, and th…
java Command: Run JARs & Classes in CIjava launches the JVM to run classes and JARs. Reference for -jar, -cp, --module-path, -D system properties,…
javac Command: Compile Java in CIjavac is the Java compiler. Reference for -d, -cp/-classpath, --release, -source/-target, -Xlint, and the pac…