Expand my Community achievements bar.

SOLVED

Adding local repo like nexus to maven and managing dependencies

Avatar

Level 2

I have use case where I want my custom bundle to be used as a dependency in another project. I've been guided to use Nexus repo and to pull dependencies from there. Problem is I'm having zero luck finding any helpful tutorials about how to connect nexus to AEM.

 

I would like to know how I can add my custom bundle to the nexus local repository and how to configure my parent pom.xml to pull in dependencies from there.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi @akatsuki07!

For your use case, there is no need to establish a connection between Nexus and AEM.

What you need to do is:

  1. Tell Maven to deploy your bundle to your Nexus repository
  2. Tell Maven to use your Nexus repository for dependency resolution

 

For 1, there is a good tutorial from Sonatype. The most important part should be to add the following to your Maven settings.xml file (either at /conf in your Maven installation or at your ~/.m2 directory):

<servers>
  <server>
    <id>nexus-snapshots</id>
    <username>deployment</username>
    <password>the_pass_for_the_deployment_user</password>
  </server>
</servers>

Along with an according entry in your projects pom.xml file:

<distributionManagement>
   <snapshotRepository>
      <id>nexus-snapshots</id>
      <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
   </snapshotRepository>
</distributionManagement>

But more details and explanations are outlined in the linked tutorial.

 

 

For 2, you will need to add your Nexus server as an additional repository for dependency resolution, e.g. to your settings.xml (see above). This is outlined in this Maven guide on how to use multiple repositories:

<repository>
  <id>nexus-repo</id>
  <name>Internal Nexus repository</name>
  <url>http://yournexus:8001/</url>
</repository>

There are several ways to include this for different purposes, e. g. by adding it to a specific profile that can be activated by default or only when specified. Please check the Maven documentation for more details.

 

 

Once you have deployed your bundle to Nexus and any consuming project is built (with dependency resolution pointing at your Nexus server), the bundle dependency will automatically be handled as with any external dependency.

 

 

Apart from these two steps you may also want to add your Nexus server as a mirror for external repositories. Please refer to this Maven guide for further details.

 

Hope that helps!

View solution in original post

2 Replies

Avatar

Community Advisor

Hi @akatsuki07,

 

In the setting.xml of your .m2 folder, you can add the nexus repo to your profile.

 

Reference link: https://maven.apache.org/settings.html#Profiles

Sample profile: https://helpx.adobe.com/experience-manager/kb/SetUpTheAdobeMavenRepository.html

 

For your use case, you need to add your custom bundle as dependency in another project - in both apps and core pom.

 

Hope this helps!

 

Thanks,

Kiran Vedantam.

Avatar

Correct answer by
Employee Advisor

Hi @akatsuki07!

For your use case, there is no need to establish a connection between Nexus and AEM.

What you need to do is:

  1. Tell Maven to deploy your bundle to your Nexus repository
  2. Tell Maven to use your Nexus repository for dependency resolution

 

For 1, there is a good tutorial from Sonatype. The most important part should be to add the following to your Maven settings.xml file (either at /conf in your Maven installation or at your ~/.m2 directory):

<servers>
  <server>
    <id>nexus-snapshots</id>
    <username>deployment</username>
    <password>the_pass_for_the_deployment_user</password>
  </server>
</servers>

Along with an according entry in your projects pom.xml file:

<distributionManagement>
   <snapshotRepository>
      <id>nexus-snapshots</id>
      <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
   </snapshotRepository>
</distributionManagement>

But more details and explanations are outlined in the linked tutorial.

 

 

For 2, you will need to add your Nexus server as an additional repository for dependency resolution, e.g. to your settings.xml (see above). This is outlined in this Maven guide on how to use multiple repositories:

<repository>
  <id>nexus-repo</id>
  <name>Internal Nexus repository</name>
  <url>http://yournexus:8001/</url>
</repository>

There are several ways to include this for different purposes, e. g. by adding it to a specific profile that can be activated by default or only when specified. Please check the Maven documentation for more details.

 

 

Once you have deployed your bundle to Nexus and any consuming project is built (with dependency resolution pointing at your Nexus server), the bundle dependency will automatically be handled as with any external dependency.

 

 

Apart from these two steps you may also want to add your Nexus server as a mirror for external repositories. Please refer to this Maven guide for further details.

 

Hope that helps!