Loading

How to publish and consume a Parent POM for your Mule Applications in Exchange

Дата публикации: Jul 15, 2025
Задача

Update the Parent-Pom Article

Действия

DESCRIPTION

You wish to standardise some components or configuration in your Mule Applications by leveraging a Parent POM file. This is either referenced by a direct link in the Filesystem to the location of the Parent POM with the <relativePath> attribute, or otherwise can be consumed from an External Repository.

Exchange now supports publication and consumption of POM files as a Custom Asset as per the documentation here: https://docs.mulesoft.com/exchange/to-create-an-asset#create-a-custom-asset

STEPS TO FOLLOW

1. Create a Parent POM file to use as a basis for our applications, an example file can be seen inline below:

<?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">
  <modelVersion>4.0.0</modelVersion>
  <name>Exchange Example Parent POM</name>
  <description>A parent pom project to be used in documentation</description>
  <groupId>[ORGANISATION_ID]</groupId>
  <artifactId>exchange-parent-pom</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <properties>
        <type>custom</type>
        <mule.maven.plugin.version>4.2.0</mule.maven.plugin.version>
        <mule-http-connector-version>1.9.3</mule-http-connector-version>
        <mule-sockets-connector-version>1.2.4</mule-sockets-connector-version>
  </properties>
  <build>
    <plugins>
        <plugin>
            <groupId>org.mule.tools.maven</groupId>
            <artifactId>exchange-mule-maven-plugin</artifactId>
            <version>0.0.23</version>
            <executions>
                <execution>
                    <id>validate</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>exchange-pre-deploy</goal>
                    </goals>
                </execution>
                <execution>
                    <id>deploy</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>exchange-deploy</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>
   <dependencies>
  <dependency>
   <groupId>org.mule.connectors</groupId>
   <artifactId>mule-http-connector</artifactId>
   <version>${mule-http-connector-version}</version>
   <classifier>mule-plugin</classifier>
  </dependency>
  <dependency>
   <groupId>org.mule.connectors</groupId>
   <artifactId>mule-sockets-connector</artifactId>
   <version>${mule-sockets-connector-version}</version>
   <classifier>mule-plugin</classifier>
  </dependency>
</dependencies>
 <repositories>
  <repository>
   <id>anypoint-exchange-v3</id>
   <name>Anypoint Exchange</name>
   <url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
   <layout>default</layout>
  </repository>
  <repository>
   <id>mulesoft-releases</id>
   <name>MuleSoft Releases Repository</name>
   <url>https://repository.mulesoft.org/releases/</url>
   <layout>default</layout>
  </repository>
</repositories>
 <pluginRepositories>
  <pluginRepository>
   <id>mulesoft-releases</id>
   <name>MuleSoft Releases Repository</name>
   <layout>default</layout>
   <url>https://repository.mulesoft.org/releases/</url>
   <snapshots>
    <enabled>false</enabled>
   </snapshots>
  </pluginRepository>
</pluginRepositories>
  <distributionManagement>
    <repository>
      <id>exchange-server</id>
      <name>Corporate Repository</name>
      <url>https://maven.anypoint.mulesoft.com/api/v3/organizations/[ORGANISATION_ID]/maven</url>
      <layout>default</layout>
    </repository>
  </distributionManagement>
</project>

Replace any instance of [YOUR_ORGANIZATION_ID] with the Org ID or Business Group ID you will be deploying this parent pom file to within Anypoint. See: How to know my Organization ID (Org ID) on the Anypoint Platform and https://docs.mulesoft.com/exchange/to-publish-assets-maven


Do also note that as per the documentation we are publishing this Custom Asset using the exchange-mule-maven-plugin instead of the mule-maven-plugin, which will be used in later steps.


Please note the below two points for successfully publishing the parent-pom to Exchange:

  1. Add property <type>custom</type>
  2. Use Exchange Facade v3 in the distribution management section.
  3. Update the exchange-mule-maven-plugin version 

Lastly ensure your settings.xml has the Private Exchange credentials configured, see: Correct usage of Exchange with Maven in particular make sure that the <id> value for the Private Exchange servers set in any pom.xml matches with the <id> value for the credentials set in settings.xml.

2. Save the above file to your filesystem in an empty directory as pom.xml, and from the directory where this pom.xml is located run the following command to deploy this POM file into your Private Exchange repository:

mvn clean deploy

Ensure that this returns a BUILD SUCCESS message, if you run into issues with this step you can enable the -e Error and -X Debug flags to get more information on any publication errors:

mvn clean deploy -e -X


3. This asset is not visible or searchable in the Exchange UI, but we can confirm this asset has been deployed successfully by creating a dependent child project and referencing the Parent POM file. To make sure this is fetched from the remote repository we will first remove the cached copy saved in our ~/.m2/repository directory, by deleting the following directory:

[USER_HOME_DIRECTORY]/.m2/repository/[YOUR_ORGANIZATION_ID]/exchange-parent-pom

If you have customised the location of the local .m2 repository cache adjust the path as needed.

4. Now we will create a simple dependent application which uses the Parent POM file to fetch some dependencies and set some properties within the POM file. Create a new project in Anypoint Studio via File > Mule Project, leaving all the options at the default. Once the new project is created overwrite the applications pom.xml file with the content below:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>[YOUR_ORGANIZATION_ID]</groupId>
<artifactId>exchange-child-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>mule-application</packaging>
 <name>exchange-child-project</name>
 <parent>
  <groupId>[YOUR_ORGANIZATION_ID]</groupId>
    <artifactId>exchange-parent-pom</artifactId>
    <version>1.0.0</version>
</parent>
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

  <app.runtime>4.4.0-20220523</app.runtime>
</properties>
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <version>3.0.0</version>
   </plugin>
   <plugin>
    <groupId>org.mule.tools.maven</groupId>
    <artifactId>mule-maven-plugin</artifactId>
    <version>${mule.maven.plugin.version}</version>
    <extensions>true</extensions>
      <configuration>
        <classifier>mule-application</classifier>
      </configuration>
   </plugin>
  </plugins>
</build>
 <repositories>
  <repository>
   <id>anypoint-exchange-v3</id>
   <name>Anypoint Exchange</name>
   <url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
   <layout>default</layout>
  </repository>
  <repository>
   <id>mulesoft-releases</id>
   <name>MuleSoft Releases Repository</name>
   <url>https://repository.mulesoft.org/releases/</url>
   <layout>default</layout>
  </repository>
  <repository>
          <id>exchange-server</id>
          <name>Corporate Repository</name>
          <url>https://maven.anypoint.mulesoft.com/api/v3/organizations/[YOUR_ORGANIZATION_ID]/maven</url>
          <layout>default</layout>
        </repository>
</repositories>
  <distributionManagement>
    <repository>
      <id>exchange-server</id>
      <name>Corporate Repository</name>
      <url>https://maven.anypoint.mulesoft.com/api/v3/organizations/[YOUR_ORGANIZATION_ID]/maven</url>
      <layout>default</layout>
    </repository>
  </distributionManagement>
 <pluginRepositories>
  <pluginRepository>
   <id>mulesoft-releases</id>
   <name>MuleSoft Releases Repository</name>
   <layout>default</layout>
   <url>https://repository.mulesoft.org/releases/</url>
   <snapshots>
    <enabled>false</enabled>
   </snapshots>
  </pluginRepository>
</pluginRepositories>
</project>

Replace any instance of [YOUR_ORGANIZATION_ID] with your Organization or Business Group ID (these values must match between parent and child POM files).

5. Now with the Parent and Child POM files configured and the local copy of the Parent POM deleted we can test that this application builds correctly by either trying to deploy it in Studio, or by packaging it with Maven on the command line by navigating to the directory where the applications POM file is located and using the command:

mvn clean package

The above should report a BUILD SUCCESS message, investigate any issues or BUILD FAILURES with the error and debug flags as before:

mvn clean package -e -X


The application can now be built and deployed from any machine correctly configured to fetch assets from your Private Exchange repository.

 

 

Номер статьи базы знаний

001116554

 
Загрузка
Salesforce Help | Article