Author: Payal Jain
In real-time projects, we re-use the dependencies across projects and APIs, and a parent POM becomes very useful in such requirements.
It is useful to manage shared resources and have a single point of modification to update our projects. The parent POM file is a maven project that can be referenced by a MuleSoft API pom.xml file 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, and every project would update their 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 required properties version details needed to be referenced from the main project:
<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:

- Add 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>

- Add our 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>

Note: Corresponding Exchange’s Username and password must be present in our local .m2 folder for Maven->conf->settings.xml location 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 our local.
- It will deploy your Parent POM in exchange, but it can’t be viewed directly in Exchange. To verify the deployment run the maven command in our main project (after making necessary changes in the main project’s POM file to refer to the parent POM). We could see the client-parent-pom folder created under .m2/ after this run, which implies Parent POM is deployed correctly.
- Changes to be made in the main project’s POM.
Add below detail:
<parent>
<groupId>*******</groupId>
<artifactId>client-parent-pom</artifactId>
<version>1.0.0</version>
</parent>

- 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>


- The main differences are that we have the “parent” element and that we are using a Maven property to specify the HTTP Connector version. Also, we can see that the Maven property to set the HTTP connector is not present in this pom.xml but instead in the parent POM.
- This is very useful if we have multiple projects and we have to update the versions to the latest one with one change in parent POM without impacting other main projects’ POM files.