News and Notes from the Makers of Nexus | Sonatype Blog

How to Use Sonatype Nexus Repository with Maven Deploy

Written by Awkash Agrawal | May 11, 2020

Most of the time, it is fairly difficult for a junior developer to make sense of things happening behind the scenes. This happened in one of my interactions with a junior developer recently. I asked, "what happens when you do a Maven deploy and Maven install?". I did not get the expected answer. Therefore, I felt that showing a practical example would help that person understand the activities happening behind the scenes, and could help you too.

I divided this tutorial into a series of easy-to-follow steps, below. I also recorded a video that demonstrates each step. If you are brand new to the topic, check out the free class Sonatype offers called, " Repository Management Basics."

 

Step 1 - Create a snapshot repository for publishing the artifact on Sonatype Nexus Repository Community Edition or Sonatype Nexus Repository. (To learn more about snapshot repositories and release repositories, refer to this discussion on Stack Overflow.)

Step 2 - Create a release repository used to publish the artifact to production.

Step 3 - Create a group repository, which is a combination of snapshot and release repo put together.

Step 4 - Download the initializer project from spring.io to create a sample project that will be published to the repository.

Step 5 - Configure settings in XML file related to Maven. To learn more about settings, please refer to this post by mykong.

Step 6 - Create profiles in Maven, a concept used to group certain configurations under one heading. Here are some additional resources:

Step 7 - Configure the credentials of your Nexus server.

Step 8 - Configure release and snapshot repo created in Step 1 and 2 on the Maven side. This will allow Maven to publish the artifact to the repo.

Step 9 - Double check the repo id matches.

Step 10 - Run the command for publishing an artifact to Sonatype Nexus Repository.

Steps 11 and 12 - Publish the artifact to release repo using a different profile in Maven.