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. For information on Maven see See Also.

Notes:

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

  • The Group ID must be set to the Organization ID.

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:

    ex2-organization-id

  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.

    Note: Only these values are accepted in a <type> statement: connector, custom, example, extension, http-api, raml-fragment, rest-api, soap-api, and template. Any other type is set to unknown.

    
                
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    <?xml version="1.0" encoding="UTF-8"?>
    <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">
    
      <name>Asset name</name>
      <description>Asset description</description>
      <properties>
        <type>example</type>
      </properties>
    
      ...
    
      <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>
      ...
    </project>
  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-login>\.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.


         
      
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>SAME_AS_ORGANIZATION_ID/groupId>
      <artifactId>ARTIFACT_ID</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/ORGANIZATION_ID/maven</url>
      <layout>default</layout>
    </repository>
  </repositories>
 ...
</project>

Replace ORGANIZATION_ID with your organization ID, and set this same value to the GROUP_ID.

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 your .m2/settings.xml 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>

See Also