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.

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:

    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.

    
                
             
    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:


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

Replace ORGANIZATION_ID with your organization ID.

See Also