DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • MDC Logging With MuleSoft Runtime 4.4
  • MuleSoft Integration With RabbitMQ
  • Understanding CIDRs and Public vs Private IPs
  • How to Connect to Splunk Through Anypoint Studio in 10 Steps

Trending

  • A Hands-On ABAP RESTful Programming Model Guide
  • Building a Skill-Based Agentic Reviewer with Claude Code: A Practical Guide Using Skills.MD, MCP Servers, Tools, and Tasks
  • The Middleware Gap in AI Agent Frameworks
  • Evolving Spring Boot APIs to an Event-Driven Mesh
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Publishing MuleSoft Common Assets or Libraries to Anypoint Exchange and Nexus

Publishing MuleSoft Common Assets or Libraries to Anypoint Exchange and Nexus

In this tutorial, we are going to learn how to publish the MuleSoft common library, assets, or applications to Anypoint Exchange and Nexus repository.

By 
Jitendra Bafna user avatar
Jitendra Bafna
·
Jan. 22, 21 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
17.7K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

It is very important to keep common libraries or assets at a central location or repository which can be easily used across multiple applications and maintaining multiple versions of libraries in an efficient manner.

Anypoint Exchange is the MuleSoft provided hub or repositories where you can discover various built-in connectors, assets, templates and even you can store your own libraries, assets, etc. Anypoint Exchange is very much capable of storing and maintaining multiple versions of the same assets, libraries, templates, utilities, etc.

Nexus is the code repository for storing the application, common libraries, assets, or utility binaries. It is very much capable of storing and maintaining multiple versions of the same assets, libraries, templates or utilities, etc. 

In this tutorial, we are going to learn how to publish the common library, assets, or applications to Anypoint Exchange and Nexus repository.

Publishing the Assets to Anypoint Exchange

Step 1: Add Anypoint Exchange Credentials Into settings.xml of Your Local .m2 Repository

You need to add the Anypoint Platform username and password in the settings.xml of your local maven repository. Add the below entry with the correct Anypoint username and password in the settings.xml.

XML
 




x


 
1
<servers>
2
  <server>
3
    <id>MuleRepository</id>
4
    <username>Anypoint_Username</username>
5
    <password>Anypoint_Password</password>
6
  </server>
7
</servers>



In this case, the serverId defined in settings.xml is very important and we will be using the same Id in pom.xml for distributionManagement and repository.

Step 2: Add Anypoint Exchange Distribution Management in POM.xml of Your Common Library

In this step, you need to define the distributionManagement. Here, you will define the URL of Anypoint Exchange where you need to publish your libraries.

XML
 




xxxxxxxxxx
1


 
1
<distributionManagement>
2
<repository>
3
<id>MuleRepository</id>
4
<name>Corporate Repository</name>
5
<url>https://maven.anypoint.mulesoft.com/api/v1/organizations/{orgId}/maven</url>
6
<layout>default</layout>
7
</repository>
8
</distributionManagement>



Theidvalue must be matched with theserverIddefined in the settings.xml of the local maven repository. In this case, the id isMuleRepository.

You need to replace theorgIdin the URL with Anypoint Platform Organization ID. It can be retrieved from Anypoint Platform => Access Management => Click on your organization.

Step 3: Add Classifier as Mule-Plugin for Mule-Maven-Plugin

When you created the MuleSoft application, you will find the mule-maven-plugin in your pom.xml and you need to add a classifier as a mule-plugin.

XML
 




xxxxxxxxxx
1
10
9


 
1
<plugin>
2
<groupId>org.mule.tools.maven</groupId>
3
<artifactId>mule-maven-plugin</artifactId>
4
<version>${mule.maven.plugin.version}</version>
5
<extensions>true</extensions>
6
<configuration>
7
<classifier>mule-plugin</classifier>
8
</configuration>
9
</plugin>



There are various classifiers available but in this case, we will be using mule-plugin as the classifier.

Step 4: Update GroupId as OrganizationId in POM.xml

You need to update GroupId in your pom.xml as Anypoint Platform Organization Id and it has been explained above howOrganizationIdcan be retrieved from Anypoint Platform.

Step 5: Publish the Common Library to the Anypoint Exchange

You just need to execute the mvn deploy command to publish any assets or libraries to Anypoint Exchange.

Plain Text
 




xxxxxxxxxx
1


 
1
mvn deploy



Using Common Libraries or Utilities From Anypoint Exchange Into the Mulesoft Application

Once you have published the libraries, assets, or utilities in the Anypoint exchange, you can go to Anypoint Exchange and look for your libraries and copy the dependency snippets and add them to the pom.xml of the application.

dependency snippets in maven

You need to also add the repository in your application pom.xml:

XML
 




x


 
1
<repository>
2
  <id>MuleRepository</id>
3
  <name>Anypoint Exchange Repository</name>         <url>https://maven.anypoint.mulesoft.com/api/v1/organizations/{orgId}/maven</url>
4
  <layout>default</layout>
5
</repository>



You need to make sure thatidmatches with your settings.xmlserverIdandorgIdcan be extracted from the Anypoint Platform.

Publishing the Common Library to Anypoint Exchange

Step 1: Add Nexus Server Credentials Into settings.xml of Your Local .m2 Repository

You need to add the Nexus repository username and password in the settings.xml of your local maven repository. Add the below entry with the correct Nexus username and password in the settings.xml.

XML
 




x


 
1
<servers>
2
  <server>
3
    <id>NexusRepository</id>
4
    <username>Nexus_Username</username>
5
    <password>Nexus_Password</password>
6
  </server>
7
</servers>


In this case, theserverIddefined in settings.xml is very important and we will be using the same Id in pom.xml for distributionManagement and repository.

Step 2: Add Nexus Distribution Management in POM.xml of your Common library

In this step, you need to define the distributionManagement. Here, you will define the URL of Nexus where you need to publish your libraries.

XML
 




xxxxxxxxxx
1


 
1
<distributionManagement>
2
<repository>
3
<id>NexusRepository</id>
4
<name>Nexus Repository</name>
5
<url>http://localhost:8081/repository/maven-releases/</url>
6
</repository>
7
</distributionManagement>
8
 
          


Step 3: Add Maven Plugin in pom.xml

XML
 




xxxxxxxxxx
1
40


 
1
<plugin>
2
<artifactId>maven-deploy-plugin</artifactId>
3
<version>2.8.1</version>
4
<executions>
5
<execution>
6
<id>default-deploy</id>
7
<phase>deploy</phase>
8
<goals>
9
<goal>deploy</goal>
10
</goals>
11
</execution>
12
</executions>
13
</plugin>
14
 
          
15
<plugin>
16
<groupId>org.apache.maven.plugins</groupId>
17
<artifactId>maven-deploy-plugin</artifactId>
18
<version>2.8.1</version>
19
<configuration>
20
<skip>true</skip>
21
</configuration>
22
</plugin>
23
 
          
24
<plugin>
25
<groupId>org.sonatype.plugins</groupId>
26
<artifactId>nexus-staging-maven-plugin</artifactId>
27
<version>1.5.1</version>
28
<executions>
29
<execution>
30
<id>default-deploy</id>
31
<phase>deploy</phase>
32
<goals>
33
<goal>deploy</goal>
34
</goals>
35
</execution>
36
</executions>
37
<configuration>
38
<serverId>nexus</serverId>
39
<nexusUrl>http://localhost:8081/nexus/</nexusUrl>
40
<skipStaging>true</skipStaging>
41
</configuration>
42
</plugin>


Step 4: Publish the Common Library to the Anypoint Exchange

You just need to execute themvn deploycommand to publish any assets or libraries to the Nexus.

XML
 




xxxxxxxxxx
1


 
1
mvn deploy


Using Common Libraries or Utilities From Nexus in the Mulesoft Application

Once you have published the libraries, assets, or utilities in the Anypoint exchange, you can go to Anypoint Exchange and look for your libraries and copy the dependency snippets and add them to the pom.xml of the application.

You need to also add the repository in your application pom.xml:

XML
 




xxxxxxxxxx
1


 
1
<repository>
2
<id>NexusRepository</id>
3
<name>Mule Nexus Repository</name>
4
<url>http://localhost:8081/repository/maven-releases/</url>
5
<layout>default</layout>
6
</repository>



Here are the few videos provided step by step guide about publishing the assets and libraries to Anypoint Exchange and Nexus.

Now you know how to publish the MuleSoft libraries or assets to Anypoint Exchange and Nexus.

Library Nexus (standard) MuleSoft application Repository (version control) XML

Opinions expressed by DZone contributors are their own.

Related

  • MDC Logging With MuleSoft Runtime 4.4
  • MuleSoft Integration With RabbitMQ
  • Understanding CIDRs and Public vs Private IPs
  • How to Connect to Splunk Through Anypoint Studio in 10 Steps

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook