mvn deploy: Usage, Options & Common CI Errors
The final lifecycle phase - push the artifact to a remote repository.
deploy is the final phase of the Maven default lifecycle. It copies the final artifact to a remote repository so it can be shared with other developers and projects, typically a Nexus, Artifactory, or Maven Central staging repository.
What it does
deploy runs the full lifecycle through install, then uploads the artifact and POM to the repository defined in <distributionManagement> (snapshot vs release URL chosen by the version suffix). Credentials come from a matching <server> entry in settings.xml.
Common usage
mvn deploy
mvn deploy -DskipTests
mvn deploy --settings ci-settings.xml # CI settings with server credentials
mvn deploy -DaltDeploymentRepository=id::default::https://repo.example.com/snapshotsCommon error in CI (and the fix)
Symptom: "Failed to deploy artifacts: Could not transfer artifact ... Return code is: 401, ReasonPhrase: Unauthorized" or "status: 401 Unauthorized". Cause: missing or mismatched credentials. Fix: add a <server> in settings.xml whose <id> exactly matches the repository <id> in distributionManagement, supply username/password (or token) via CI secrets, and pass --settings to point Maven at that file.