Using Maven to publish parent and main project POMs to Exchange

  • December 16, 2022

In real-time projects, a parent POM is very useful because we re-use dependencies across projects and APIs.

It’s useful to manage shared resources and have a single point of modification to update projects. The parent POM file is a Maven project that a MuleSoft API pom.xml file can reference to get additional information, like properties.

Example: If we have the HTTP Connector version specified in a parent POM, then any project depending on that parent POM can be rebuilt with Maven after changing the parent POM HTTP Connector version. Every project would then update its internal HTTP Connector without actually modifying the API at all.

  • Create a new parent POM Mule project with the following details in the POM file
<groupId>**********</groupId>
<artifactId>client-parent-pom</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
  • Add the required Properties version details that the main project must reference
<app.runtime>4.4.0</app.runtime>
<mule.maven.plugin.version>3.7.1</mule.maven.plugin.version>
<mule-http-connector-version>1.5.23</mule-http-connector-version>
  • Add <type>custom<type> under the Properties tag

Properties tag

  • Add the Mule Maven plugin details
<plugin>
<artifactId>exchange-mule-maven-plugin</artifactId>
<groupId>org.mule.tools.maven</groupId>
<version>0.0.17</version>
<inherited>false</inherited>
<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>

mule maven plugin details

  • Add the repository details under distribution management with the correct groupId and version as v2
<distributionManagement>
<repository>
<id>Exchange2</id>
<name>Anypoint Platform Exchange Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v2/organizations/*****/maven</url>
<layout>default</layout>
</repository>
</distributionManagement>

Add repository details under distribution management

NOTE: The username and password of the corresponding Exchange Server must be in the local .m2 folder with the Maven ->conf ->settings.xml location set as:

<server>
<id>Exchange2</id>
<username>{add_anypoint_username}</username>
<password>{add_anypoint_password}</password>
</server>
  • Run the ‘mvn’ clean install deploy command from the parent POM’s folder in the local

It will deploy the parent POM in Exchange, but it can’t be viewed directly in Exchange. To verify the deployment, run the Maven command in the main project (after making the necessary changes in the main project’s POM file to refer to the parent POM). After this run, you’ll see the client-parent-pom folder created under .m2/, which implies the parent POM has deployed correctly.

Changes to be made in the main project’s POM

  • Add the following details:
<parent>
        <groupId>*******</groupId>
        <artifactId>client-parent-pom</artifactId>
        <version>1.0.0</version>
    </parent> 

client parent pom

  • Replace the actual version with a placeholder
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-http-connector</artifactId>
<version>${mule-http-connector-version}</version>
<classifier>mule-plugin</classifier>
</dependency>

Replace the actual version with a placeholder

Replace the actual version with a placeholder

The main differences are that you have the “parent” element and are using a Maven property to specify the HTTP Connector version. Also, you can see that the Maven property used to set the HTTP connector isn’t present in this pom.xml but is instead in the parent POM.

This is very useful if you have multiple projects and need to update the versions to the latest one via one change in parent POM without impacting the POM files of other main projects.

— By Payal Jain