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. Modify the groupId of the Maven project to be your Organization ID in your project’s POM file:

    
                
             
    1
    2
    3
    
     ...
     <groupId>ORGANIZATION_ID</groupId>
     ...
  2. Add the asset type in properties part in your project’s POM file. For example:

    
                
             
    1
    2
    3
    4
    5
    6
    7
    8
    
     ...
     <properties>
      ...
      <mule.version>3.9.0</mule.version>
      <mule.tools.version>1.2</mule.tools.version>
      <type>template</type>
     </properties>
     ...

    Note: If the <type> element is not included, your upload may succeed but not be displayed in Exchange. You need to ensure that this element contains one of the following values for your asset to be visible in Exchange: connector, extension, template, example, rest-api, soap-api, http-api, raml-fragment, custom.

  3. 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>
      ...
  4. 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>
  5. Publish your asset to Exchange using the Maven mvn deploy command.

About a Private Exchange Access URL

After you know your organization ID, you can use the following URL syntax to share the location of an asset:

Substitute ORGANIZATION_ID for the private Exchange’s organization ID and ASSET_ID for the asset ID.

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.

If you are publishing your asset to the master organization, the group ID is the same as the organization ID. The URL format is:

https://maven.anypoint.mulesoft.com/api/v1/organizations/ORGANIZATION_ID/maven

If you are publishing your asset to a business group, the group ID is the same as the business group ID. The URL format is:

https://maven.anypoint.mulesoft.com/api/v1/organizations/BUSINESS_GROUP_ID/maven


         
      
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>