Nav

To Publish and Deploy Exchange Assets Using Maven

Anypoint Exchange provides a Maven facade that enables Maven clients to publish and consume assets using Maven.

Prerequisites

This document assumes you are familiar with Maven, programming concepts, and command line operations on your computer or server.

Note: You must have a unique artifact name and organization ID to publish your asset.

To View Your Organization ID

  1. Log into Anypoint Platform and click Access Management.

  2. Click your top level organization name.

  3. View the organization ID in the URL in the browser address bar:

    Screenshot - Locating an organization ID in a URL

    For example, in this URL:

    https://anypoint.mulesoft.com/accounts/#/cs/core/organizations/ORG_ID/edit

    The Organization ID would appear where the ORG_ID placeholder is shown.

  4. Copy the organization ID and add it to the examples that follow for how to set up your project’s POM file.

To Publish an Asset to Exchange Using Maven

  1. Add the Maven facade as a repository in the distribution management section of your project’s POM file:

    
                
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
     ...
      <distributionManagement>
        <repository>
          <id>Repository</id>
          <name>Corporate Repository</name>
          <url>https://maven.anypoint.mulesoft.com/api/v1/organizations/ORGANIZATION_ID/maven</url>
          <layout>default</layout>
        </repository>
      </distributionManagement>
      ...
  2. Update the settings.xml file in your Maven .m2 directory. After you install Maven, the mvn clean command creates the .m2 directory. On a Mac, the directory resides at ~/.m2 whereas under Windows, the directory resides at <default-drive>\Users\YOUR_USER_NAME\.m2 that contains your Anypoint Platform credentials. The Maven client reads the settings file when Maven runs.

    Example settings.xml file:

    
                
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <servers>
        <server>
          <id>Repository</id>
          <username>myusername</username>
          <password>mypassword</password>
        </server>
      </servers>
    </settings>
  3. Publish your asset to Exchange using the Maven mvn deploy command.

To Consume an Exchange Asset with Maven

Add the asset’s groupID, artifactID, and version to the dependencies section of your project’s pom.xml file, and add the Maven facade as a repository in the repositories section.

The Group ID must be the same value as the Organization ID if you are publishing your asset to the master organization. If you are publishing to a business group, the group ID is formed by the masterOrgId plus all the business group names in the hierarchy until you reach your org, joined by '.' For example: masterOrgId.BG1Name.BG1.2Name.BG1.2.1Name.


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
 ...

  <dependencies>
    <dependency>
      <groupId>org.mule.modules</groupId>
      <artifactId>mule-module-metoo</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>

 ...

  <repositories>
    <repository>
      <id>Repository</id>
      <name>Corporate Repository</name>
      <url>https://maven.anypoint.mulesoft.com/api/v1/organizations/ORG_ID/maven</url>
      <layout>default</layout>
    </repository>
  </repositories>
 ...
</project>

Replace ORG_ID with your organization ID.

You can use https://maven.anypoint.mulesoft.com/api/v1/maven as a valid URL for the <url> value, as this is the default to publish to the master organization.

To Publish Federated Assets

  1. Get the access token by logging into Anypoint Platform and copying this URL to the browser address bar:

    https://anypoint.mulesoft.com/accounts/api/profile
  2. Search for access_token in the displayed values.

  3. Add the access token to the ~/.m2/settings.xml (Mac or Linux), or C:\Users\YOUR_USER_NAME\.m2\settings.xml (Windows) file:

    
                
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
              http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <servers>
        <server>
          <id>Repository</id>
          <username>~~~Token~~~</username>
          <password>ACCESS_TOKEN</password>
        </server>
      </servers>
    </settings>