Publishing Local JARs to a Private Nexus Repository
To push a local Java archive to an internal Nexus server, the Maven deploy plugin is required. Begin by defining the repository details with in the project's pom.xml under the distributionManagement node:
<project>
<distributionManagement>
<repository>
<id>enterprise-releases</id>
<name>Corporate Release Storage</name>
<url>https://nexus.internal.net/repository/maven-releases/</url>
</repository>
</distributionManagement>
</project>
The id element must align with the server authentication block configrued in the Maven settings.xml file. Add the corresponding credentials inside the <servers> section:
<settings>
<servers>
<server>
<id>enterprise-releases</id>
<username>deploy-user</username>
<password>s3cr3tP@ss</password>
</server>
</servers>
</settings>
With the authentication mapping established, execute the deploy:deploy-file goal from the terminal. This command bypasses the standard build lifecycle and directly transfers the specified artifact:
mvn deploy:deploy-file \
-DgroupId=com.corp.library \
-DartifactId=custom-utils \
-Dversion=1.0.0 \
-Dpackaging=jar \
-Dfile=./target/custom-utils-1.0.0.jar \
-Durl=https://nexus.internal.net/repository/maven-releases/ \
-DrepositoryId=enterprise-releases
Replace the coordinate parameters (groupId, artifactId, version) and the file path with the actual values for the target archive. The url and repositoryId flags dictate the destination and reference the ID used in settings.xml for credential resolution.