Saturday, 3 October 2020

How to push maven artifacts to Nexus Repository

 In this post we will discuss mainly on how we can push maven artifacts to Nexus repository.

In the pom.xml file please add below content. Please replace {{ NEXUS_HOST }} and {{ NEXUS_PORT  }}as per your environment setup. 

<distributionManagement>

   <snapshotRepository>

  <id>maven-snapshots</id>

  <url>http://{{ NEXUS_HOST }}:{{ NEXUS_PORT }}/repository/maven-snapshots/</url>

   </snapshotRepository>

<repository>

<id>maven-releases</id>

<url>http://{{ NEXUS_HOST }}:{{ NEXUS_PORT }}/repository/maven-releases/</url>

</repository>

</distributionManagement>


Add below lines in plugins section in pom.xml

<plugin>

   <artifactId>maven-deploy-plugin</artifactId>

   <version>2.8.1</version>

   <executions>

  <execution>

<id>default-deploy</id>

<phase>deploy</phase>

<goals>

<goal>deploy</goal>

</goals>

  </execution>

   </executions>

</plugin>


To Authenticate with Nexus we need to provide creds in settings.xml. Please add below content in settings.xml. Please update {{NEXUS_USERNAME}} and {{NEXUS_PASSWORD}} as per your environment. 

Under <servers> section please add below content and save file.

   <server>

      <id>maven-snapshots</id>

      <username>{{NEXUS_USERNAME}}</username>

      <password>{{NEXUS_PASSWORD}}</password>

   </server>

   <server>

      <id>maven-releases</id>

      <username>{{NEXUS_USERNAME}}</username>

      <password>{{NEXUS_PASSWORD}}</password>

   </server>


Now you are good to push maven artifacts to Nexus 3 repository manager. Please run mvn deploy to push maven artifacts to Nexus repo.


No comments:

Post a Comment