MuleSoft Technical Guides

Mule Maven Plugin

User MuleSoft Integration Team
Calendar March 03, 2022

One of the ways to deploy the MuleSoft Application is using the Mule Maven Plugin.

In Mule 4, when the new project is created, we find pom.xml in the project structure.

Pom.xml file contains the dependency information of the modules used in the project.

It manages dependencies which are required to run the application.

Steps to deploy the MuleSoft Application using Mule Maven Plugin are as follows:

  1. Make sure Maven is installed in your system.
  2. Create MuleSoft Project in AnypointStudio

As mule 4 projects are mavenised, so we have a pom.xml file created in the project.

The MUnit code coverage should be more than 70-80% before deploying the application.

3. Add configuration in pom.xml file

Copy Paste <configuration> tag in mule plugin section  in pom.xml

<plugin>
		<groupId>org.mule.tools.maven</groupId>
		<artifactId>mule-maven-plugin</artifactId>
		<version>${mule.maven.plugin.version}</version>
		<extensions>true</extensions>
		<configuration>
			<cloudHubDeployment>
				<muleVersion>{mule.version}</muleVersion>
				<username>${username}</username>
				<password>{password}</password>
				<environment>${environment}</environment>
				<applicationName>${application.name}</applicationName> 
				<workers>${workers}</workers>
				<workerType>${worker.type}</workerType>
				<objectStoreV2>true</objectStoreV2>
			</cloudHubDeployment>
		</configuration>
	</plugin>

Note:  

  • Maven Credentials should be passed through Secrets (It might be AWS, Jenkin, Azure etc).
  • Property Masking should be done to mask the credentials at runtime properties in mule-artifact.json file as shown below: 

 {

  "minMuleVersion": "4.3.0",

  "secureProperties": ["mule.key"]

}

4. Run Maven Commands to deploy Application to CloudHub

  • Open Command prompt from the Project Workspace location.
  • Run below commands in command prompt.

mvn clean install: This command will delete all existing compiled files. Make sure the build should be successful.

mvn package deploy: Refer below command to deploy the application to CloudHub and replace the credentials with your Anypoint Platform Credentials.

mvn package deploy -Dusername=MuleSoftUser-Dpassword=password -Denvironment=Sandbox 
-Dmule.version=4.3.0 -Dworkers=1 
-Dworker.type=Micro -Dapplication.name=mule-demo-application  
-DmuleDeploy

A jar file automatically will get created then the application will be deployed to Anypoint Platform.

Go to the Runtime Manager and check the status of the Application.

You can test the application when the status changes to “Started”.

While deploying the application, you may face few errors.

  1. Validation exception: The following mandatory fields in the mule-artifact.json are missing or invalid:
  • [name,classLoaderModelLoaderDescriptor, classLoaderModelLoaderDescriptor.id, requiredProduct]. requiredProduct valid values are: MULE, MULE_EE -> [Help 1]

To resolve this error, update missing name, classLoaderModelLoaderDescriptor, requiredProduct in mule-artifact.json file.

mule-artifact.json

{
  "name": "mule-maven-plugin-poc",
  "minMuleVersion": "4.3.0",
  "secureProperties": ["mule.key"],
  "requiredProduct": "MULE_EE",
  "classLoaderModelLoaderDescriptor": {
    "id": "mule",
    "attributes": {
      "exportedResources": []
    }
  }
}
  1. mule.tools.client.standalone.exception.DeploymentException: Domain is not available. Aborting.

This error occurs due to duplicate application name in CloudHub, and rename it with a unique name.

  1. 400 Bad Request: {“status”:400,”message”:”Object Store V1 is not supported for your org”}

 

Find more MuleSoft Technical Guides at Caelius Consulting’s Resource Centre.

Leave a comment

Your email address will not be published. Required fields are marked *