html code

The parent POM and the main project POM are deployed to the Maven repository for sharing

In real-world projects, the reuse of dependencies across various projects and APIs is a common practice, and a parent POM proves invaluable in such scenarios.

It serves as a central hub for efficiently managing shared resources and provides a single point for making modifications that can be applied across all our projects. The parent POM is essentially a Maven project that can be referenced by a MuleSoft API’s pom.xml file to access additional information, such as properties.

For instance, consider the HTTP Connector version specified in a parent POM. By modifying the HTTP Connector version in the parent POM and rebuilding any project dependent on it with Maven, all associated projects can seamlessly update their internal HTTP Connectors without requiring any changes to the API itself.

Generate a fresh parent POM Mule project and include the specified details in the POM file:

<groupId>**********</groupId>
<artifactId>client-parent-pom</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

Incorporate the necessary version details for properties that need to be accessed 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>

Include <type>custom</type> within the <Properties> section.

Integrate the specifics of the Mule Maven plugin.

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

Include our repository information in the distribution management section, ensuring the correct groupId and version are set to ‘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>

Please be aware that the Exchange username and password should be available within our local .m2 directory, specifically in the Maven’s ‘conf’ folder at ‘settings.xml’ location, as follows:

<server>
<id>Exchange2</id>
<username>{add_anypoint_username}</username>
<password>{add_anypoint_password}</password>
</server>

Execute the ‘mvn clean install deploy’ command from the directory of the parent POM on your local machine. This action deploys your Parent POM to the Exchange, although it won’t be directly visible in the Exchange platform. To confirm the successful deployment, execute the Maven command in your main project, ensuring you’ve made the necessary modifications to the main project’s POM file to reference the parent POM. Subsequently, you should observe the creation of the ‘client-parent-pom’ folder within the .m2/ directory, which serves as confirmation that the Parent POM has been successfully deployed. Be sure to make the required adjustments in the main project’s POM file.

Include the following information:

<parent>
        <groupId>*******</groupId>
        <artifactId>client-parent-pom</artifactId>
        <version>1.0.0</version>
    </parent> 

Substitute the current version with a temporary placeholder.

<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-http-connector</artifactId>
<version>${mule-http-connector-version}</version>
<classifier>mule-plugin</classifier>

</dependency> tag

  • The key distinctions here are the presence of the ‘parent’ element and the use of a Maven property to define the version of the HTTP Connector. Notably, you’ll observe that the configuration for the HTTP connector, in the form of a Maven property, is absent in this pom.xml and is instead located within the parent POM.
  • This proves highly advantageous when dealing with multiple projects, as it allows for a single modification in the parent POM to update all versions to the latest one, without causing any changes to the POM files of other main projects.