Skip to content
Latchkey

mvn deploy: Push to a Remote Repository

mvn deploy runs the full lifecycle and then uploads the artifact and pom to the remote repository configured in distributionManagement, using credentials from settings.xml.

deploy is the final lifecycle phase: it publishes to a shared repository (Nexus, Artifactory, Central). Most CI failures here are auth or target-repo configuration.

What it does

Invoking deploy runs through install, then the deploy phase uploads the artifact and pom to the remote repository named in the project's <distributionManagement>. The maven-deploy-plugin matches the repository id to a <server> in settings.xml to authenticate.

Common usage

Terminal
mvn -B deploy -DskipTests
# auth comes from ~/.m2/settings.xml <server> with id matching the repo
mvn deploy -DaltDeploymentRepository=releases::default::https://nexus/repo

Flags

FlagWhat it does
-DaltDeploymentRepository=<id>::<layout>::<url>Override the target repository
-DskipTestsSkip tests before deploying
--settings <file>Use a specific settings.xml with credentials
-BBatch mode for CI

In CI

Provide credentials through a CI-managed settings.xml (server id matching the repo id), and run mvn -B deploy. Never deploy a SNAPSHOT to a release repo; most servers reject a redeploy of a released version. Cache ~/.m2/repository, not the credentials.

Common errors in CI

"Failed to deploy artifacts: Could not transfer artifact ... status code 401" is wrong/missing credentials; the server id in settings.xml must match the distributionManagement id. "status code 405 Method Not Allowed" means deploying to a URL that does not accept PUT (often a proxy/group URL instead of the deployment URL). "status code 409 Conflict" is redeploying an existing release.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →