mvn install vs package: A Practical Side-by-Side

Compare mvn install and mvn package in Maven to understand when to build, package, and install artifacts for standalone use or multi-module workflows. Learn how each goal affects the local repository, CI pipelines, and downstream projects.

Install Manual
Install Manual Team
·5 min read
Quick AnswerComparison

package creates the artifact in the target directory and stops there, while install builds the artifact and also installs it into your local Maven repository for use by other projects on the same machine. package is ideal for standalone builds or CI, whereas install is essential for multi-module projects where downstream modules depend on local artifacts. In most workflows, you start with package, then run install when you need local inter-module dependencies.

Understanding the core difference between mvn install vs package

In Maven, two commonly used goals are mvn package and mvn install. The phrase mvn install vs package captures the core decision developers face during local development. The mvn package goal compiles the source, runs tests, and packages the output into a distributable artifact (jar, war, or other packaging) placed in the target directory. The mvn install goal performs the same build steps but additionally installs the resulting artifact into your local Maven repository (usually under ~/.m2/repository). This installation makes your artifact available to other projects on the same machine, enabling downstream modules to declare a dependency on the locally built artifact. The primary difference between these goals is whether artifacts are propagated to the local repository. When you’re working in a multi-module workspace or testing changes across modules, mvn install becomes essential. For standalone development and testing a single module, mvn package often suffices. The choice between mvn install vs package drives how artifacts are shared and reused within a local development environment.

What exactly happens during mvn package

Maven’s package phase assembles the final artifact (jar, war, or other packaging) after compiling sources and running tests. The resulting file lands in the target directory and is ready for distribution, deployment, or manual testing. No changes are made to the local repository by this phase. This is ideal when you want to validate the artifact itself or share it with a build system that will fetch it from a central repository. If you’re iterating quickly on a single module, package keeps the workflow simple and avoids cluttering the local cache. In CI pipelines, packaging is often followed by publishing artifacts to a remote registry or artifact repository, rather than modifying your local Maven cache.

What exactly happens during mvn install

mvn install includes all steps up to package and then adds a crucial step: installing the artifact into your local repository (~/.m2/repository). This makes the built artifact available for other local projects to depend on, enabling true inter-module workflows. In multi-module builds, downstream modules can reference artifacts produced by sibling modules without rebuilding them. Installing is optional for standalone projects, but it becomes valuable when you want a connected local development environment where multiple modules share artifacts. Note that an install should reflect the exact released artifact you want other projects to depend on; if you change the version or packaging, you should re-run the build accordingly.

The Maven build lifecycle: where package and install fit

Maven follows a lifecycle with phases like validate, compile, test, package, install, and deploy. The package phase focuses on creating a distributable artifact; the install phase advances that artifact into the local repository. In practice, many teams use sequences like mvn clean package to validate and prepare artifacts, and mvn clean install when the local repository needs to be updated for downstream module builds. Understanding this flow helps you tailor your commands to the exact outcome you need, whether you’re preparing a release artifact or enabling inter-module dependencies within your development environment.

Local repository and dependency resolution explained

Maven’s local repository is a cache of artifacts downloaded from remote repositories and artifacts built locally. When you run mvn install, your newly created artifact is placed in ~/.m2/repository and can be discovered by other projects on the same machine. Dependency resolution relies on a combination of local cache and remote repositories, with version ranges and scopes affecting how artifacts are retrieved. If a module needs a sibling artifact, an installed artifact in the local repository makes the resolution deterministic for that workspace. Without a local install, downstream modules would require a round of builds to produce the needed artifacts, which can slow down development workflows.

When to choose package: best scenarios

Choose mvn package when you want a clean, distributable artifact without altering your local repository. Package is ideal for validating the artifact with a standalone deployment, creating a binary for distribution, or sharing an artifact with a CI system that will pull from a remote registry. It keeps the local environment uncluttered and minimizes risk of accidental cross-module dependencies. If your goal is to generate a testable artifact quickly, package is the natural first step in many development workflows.

When to choose install: best scenarios

Maven install shines in multi-module projects or when you want your local modules to depend on each other. Installing the artifact enables downstream modules to reference the exact version without rebuilding it, which improves consistency and speeds up development. Use install when you’re actively iterating across modules, testing integration between modules, or preparing a reproducible local build environment. In CI environments that simulate real packaging and deployment across modules, install ensures the local cache is up to date and consistent with the project’s intended dependencies.

Practical examples with commands

  • mvn clean package -DskipTests: builds the project, packages the artifact, and skips tests for faster feedback during initial validation.
  • mvn clean package: standard workflow to verify compilation, tests, and artifact packaging without affecting the local repository.
  • mvn clean install: builds, tests, packages, and installs the artifact into the local repository for other modules to depend on.
  • mvn -DskipTests clean install -Pci: a CI-friendly sequence that compiles and installs with tests skipped and a dedicated profile.
  • For multi-module projects, consider mvn -pl module-a,module-b -am clean install to build affected modules and their dependencies, then install the final artifacts locally.

Common pitfalls and how to avoid them

  • Assuming package updates downstream modules automatically; without install, dependencies won’t be resolved locally. Avoid this by planning an install step when you need local inter-module sharing.
  • Skipping tests in a way that hides failures; consider running full tests before deciding to package or install for release candidates.
  • Mixing SNAPSHOT and release versions without proper versioning; use clear versioning strategies and consistent tagging to prevent drift.
  • Relying on a local repository that isn’t synchronized with your remote registries; ensure your settings.xml references the correct mirrors and repositories.
  • Running install in a clean CI without ensuring artifact integrity; validate artifacts prior to deployment by using package first, then install in a controlled environment.

Impact on CI/CD and multi-module projects

In CI/CD pipelines, packaging is typically used to validate and produce artifacts that are then uploaded to a central repository. If the pipeline includes downstream modules within the same project, an install step can be used to propagate the artifact into the local repository, allowing downstream stages or jobs to resolve dependencies without re-building. For multi-module projects, the combination of package and install within separate steps can reduce build times and stabilize dependency resolution across modules. Always tailor your pipeline to your repository layout, profiles, and artifact promotion strategy to minimize network load and maximize reproducibility.

Performance considerations, parallel builds, and caching

Maven performance can be influenced by how you structure builds and caches. Enabling parallel builds with -T 1C can speed up module-heavy projects, though it requires careful handling of shared resources. Using the local repository cache helps avoid repeated downloads for each run, especially when running multiple builds locally. Skipping tests or running with light profiles can dramatically reduce build time during early development, but re-enable thorough validation before release. In all cases, a clear policy on when to package versus install helps balance speed with reliability.

Authority references and further reading

  • Official Maven build lifecycle guide: https://maven.apache.org/guides/introduction/introduction-to-the-build-life-cycle.html
  • Getting started with Maven: https://maven.apache.org/guides/getting-started/index.html
  • Maven Install Plugin documentation: https://maven.apache.org/plugins/maven-install-plugin/ These references provide authoritative detail on how packaging and installation interact with the Maven lifecycle, repository resolution, and project structuring.

Comparison

Featuremvn packagemvn install
Artifact produceddistributable artifact in target (jar/war/...)artifact produced and installed to local repository (~/.m2/repository)
Local repositoryno change to local repoartifact copied to local repo for downstream use
Best use casestandalone artifact for testing/distributionmulti-module projects or local inter-module dependencies
Downstream impactno local dependency resolutionenables downstream modules to resolve installed artifacts
CI/CD implicationpackaging step only in CI, then publish to remote registrylocal install can power multi-module builds in CI when needed

Positives

  • Produces a standalone artifact ready for distribution
  • Faster local iterations when you don’t need to install
  • Prepares for deployment or remote publishing without mutating local cache
  • Supports clean multi-module workflows when combined with install

Disadvantages

  • Install adds an extra step and time to the local build
  • Not ideal for CI pipelines that only need packaging and publishing to a remote registry
  • Requires correct local repository configuration to avoid issues
  • Can lead to stale local artifacts if versioning is not managed carefully
Verdicthigh confidence

mvn install is generally preferable for multi-module or closely coupled projects; mvn package is best for standalone artifact validation and distribution.

Choose package to validate and produce a distributable artifact. Choose install when downstream modules depend on local artifacts. In CI, combine both thoughtfully to balance speed and reproducibility.

Got Questions?

What is the practical difference between mvn package and mvn install?

Maven package creates a distributable artifact in the target directory, while mvn install also copies that artifact into the local repository for downstream module use. The choice depends on whether you need local sharing of artifacts across modules.

Package builds the artifact. Install puts it in your local repo for other modules to depend on. Use package for standalone artifacts and install for multi-module workflows.

Can I skip tests when running mvn package or mvn install?

Yes. You can skip tests with -DskipTests or -Dmaven.test.skip=true. Skipping tests speeds up local validation but should not be used for release builds. Always enable thorough testing for final validation.

You can skip tests with -DskipTests, but avoid skipping tests for releases.

Does mvn package produce a jar or war by default?

The artifact type is determined by the project packaging setting in pom.xml (e.g., jar, war, pom). Package will produce whatever packaging is configured for the project.

The artifact type comes from the project's packaging setting; package outputs that artifact.

What happens if I run mvn install without a packaging type or with SNAPSHOT versions?

Maven will attempt to build according to the pom’s packaging and version. SNAPSHOT versions may be updated in the local repository; ensure you understand how snapshots are treated in your workflow to avoid inconsistent builds.

Maven follows the pom config, SNAPSHOT versions may update; plan accordingly.

How do I use the artifact produced by mvn install in another module?

After performing mvn install, other modules can declare dependencies on the installed artifact using standard Maven coordinates. Maven will resolve the dependency from the local repository during their builds.

Install makes the artifact available for other modules to depend on.

How does this affect CI/CD pipelines?

In CI/CD, packaging is often followed by publishing the artifact to a remote repository. If the pipeline includes multi-module components, an install step can help share artifacts across modules during the build stage.

CI often packages first, then installs if multi-module dependencies exist.

Main Points

  • Know the build goal you need before starting a task
  • Use package to create distributable artifacts without touching the local repo
  • Use install to share artifacts across modules in a local workspace
  • Plan CI/CD steps to reflect either packaging or local installation needs
Infographic comparing mvn package and mvn install lifecycle
mvn package vs mvn install: key lifecycle differences

Related Articles