Publishing an Artifact to Nexus with Maven
Fast recall
Quick revision
Core answer
section in your POM with the Nexus repository URL, store credentials in ~/.m2/settings.xml matching the server ID, and run mvn deploy to upload the artifact.Whether you understand the full build-to-publish pipeline and can configure Maven's distribution management correctly.
Putting Nexus credentials directly in `pom.xml` `<distributionManagement>` instead of in `settings.xml`, which would commit credentials to version control.
Mention the `maven-deploy-plugin`'s `deployAtEnd` feature for multi-module builds (avoids deploying partial builds), using CI environment variables for credentials, and the difference between deploying SNAPSHOTs versus release artifacts.
Interview-ready guide
Interview answer
Publishing to Nexus requires three coordinated pieces: the POM declares where to publish, settings.xml holds the credentials, and mvn deploy orchestrates the upload. The separation keeps credentials out of version control.
POM configuration
in the POM specifies both a release repository URL and a snapshot repository URL, each identified by a server ID — the ID is the link Maven uses to look up credentials insettings.xml- Maven routes automatically by version string: if the artifact version ends in
-SNAPSHOT, it goes to the snapshot repository; anything else goes to releases — the samemvn deploycommand handles both - Never put credentials in
— URLs belong in the POM, credentials belong insettings.xmlunder ablock matching the repository ID
`settings.xml` and credential management
~/.m2/settings.xmlholds theentries with username and password matching the server IDs in the POM — this file lives outside the project directory and is never committed to version control- In CI pipelines, generate
settings.xmlfrom pipeline secrets at build time rather than committing it — this keeps credentials out of the repository entirely even in CI configuration - Use encrypted passwords in
settings.xmlwithmvn --encrypt-passwordfor additional protection on shared development machines
Multi-module deploy safety
- Without
-DdeployAtEnd=true, Maven deploys each module as it builds — a failure in a later module leaves consumers with a partial, incompatible set of artifacts already published to Nexus -DdeployAtEnd=truewaits until all modules have successfully built before deploying any — either the complete consistent set ships or nothing ships
Publishing an Artifact to Nexus with Maven
Direct Answer
Configure a <distributionManagement> section in your POM with the Nexus repository URL, store credentials in ~/.m2/settings.xml matching the server ID, and run mvn deploy to upload the artifact.
Common Mistakes & Pitfalls
Putting Nexus credentials directly in pom.xml <distributionManagement> instead of in settings.xml, which would commit credentials to version control.
Check your understanding
Answer these without looking back at the article.
- What is the difference between deploying a SNAPSHOT and a release artifact in Maven?
- How does the Maven Release Plugin work and what does it do to your pom.xml?
- How do you configure a Nexus proxy repository to cache Maven Central artifacts?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.