Publish and deploy Exchange assets using Maven

  • February 07, 2020

This tech article describes how Maven can be used to deploy and consume Exchange assets using Maven Façade provided by Anypoint Exchange.

What is Maven?

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.

What is Maven Façade?

The Exchange Maven Façade API lets you interact with Exchange using the Maven client to publish and consume Exchange assets as Maven dependencies. You can use the Exchange Maven Façade API for Mule applications, templates, examples, connectors or policies.

API prerequisites and dependencies

  • To utilize this API, you must have an Anypoint Platform account
  • To use Maven, add your Anypoint Platform account username and password in the ~/.m2/settings.xml file
  • You need an Exchange Contributor or Exchange Administrator role to publish assets using the Exchange Maven API
  • This API works with Mavenized projects, including Mule applications (Mule 3.x and 4.x), templates, examples, connectors (Mule 3.x and 4.x) and policies (Mule 4.x)

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

Publish an asset to Exchange

  • Extract your organization ID:
    • Log in to Anypoint Platform and click Access Management
    • View your organization and its details from the organization panel
  • Update the group ID with the organization ID copied in your project pom.xml file

If you’re publishing your asset to the master organization, the group ID is the same as the organization ID.

If you’re publishing your asset to a business group, the group ID is the same as the business group ID.

  • Add the other necessary fields:
    • The <name> property, which represents the visible name of the asset

      If you’re publishing the first version of a GA (GroupId and AssetId combination), the asset name is taken from the POM file. If there’s already at least one version of the GA, the <name> property is ignored.
    • The <description> property, which represents the description of the asset

      If you’re publishing the first version of a GA (GroupId and AssetId combination), the asset description is taken from the POM file. If there’s already at least one version of the GA, the < description> property is ignored.

In Mule 3, enable the <type> property; otherwise, the application won’t be displayed in Exchange.

In Mule 4 assets, do not set the <type> element; instead, set the <classifier> element in the mule-maven-plugin configuration with:

  • Mule-application-template
  • Mule-application-example
  • Mule-application-policy
  • Add the Maven Façade as a repository in the distribution management section in the POM file:
    • The <id> value must be the same in the pom.xml file as in the ~/.m2/settings.xml file
  • Update the settings.xml under the ./m2 repository

    This will have the Anypoint Platform credentials; the Maven client will access settings when Maven runs
  • Open a command prompt in the project location and run the command to publish your asset to Exchange

Consume an Exchange Asset with Maven

With Maven Façade, you can consume connectors, Mule applications and REST APIs published in Exchange.

To consume an Exchange asset:

  • Add the repository under the repositories element
  • Add the Exchange asset’s groupid, artifactid and version as dependencies in your POM file under the dependency section

The asset will be downloaded and added to your project.

— By Rithul Kumar