Mule Maven Plugin for Deploying MuleSoft Applications
In this article take a look at Mule Maven Plugin for deploying MuleSoft applications.
Join the DZone community and get the full member experience.
Join For FreeWhat Is Mule Maven Plugin?
Mule Maven Plugin allows you to deploy and undeploy a MuleSoft application. It is compatible with the Enterprise Mule Runtime engine and Community Mule Kernel.
Mule Maven Plugin is capable of deploying applications automatically to on-premise, CloudHub, and Anypoint Runtime Fabric Manager.
Mule Maven plugin supports three goals:
Package: Generates jar or executable files for your Mule application.
- mvn package
Deploy: It automatically uploads, deploys and starts the application on the target system (on-premise, CloudHub, Anypoint Runtime Fabric).
- mvn deploy -DmuleDeploy
Undeploy: It automatically removes the application from the target system (on-premise, CloudHub, Anypoint Runtime Fabric).
- mvn mule:undeploy
You may also like: Deploy Mule 4 Application To Anypoint Runtime Fabric Using Maven Plugin
You can find Mule Maven Plugin in POM.xml by default whenever you create a Mule application, otherwise, you can define the plugin in POM.xml as shown below:
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>3.3.5</version>
</plugin>
Deploying a Mulesoft Application to Anypoint CloudHub Using Mule Maven Plugin
Mule Maven Plugin has the capability of deploying applications to Anypoint CloudHub. We need to understand some of the Mule Maven Plugin parameters required for deploying applications to CloudHub. Learn how to deploy a mule application in Cloudhub.
Parameter |
Description |
uri |
Your Anypoint Platform URI. If not set, by default this value is set to https://anypoint.mulesoft.com |
muleVersion |
The Mule runtime engine version that will run in your CloudHub instance. |
applicationName |
The name of your application in CloudHub. |
username |
Your Cloudhub username. |
password |
Your Cloudhub password. |
server |
Maven server with Anypoint Platform credentials. |
workers |
The number of workers. By default, it is set to 1 |
workerType |
Size of each worker. The default value is MICRO. |
environment |
The CloudHub environment to which you want to deploy. |
businessGroup |
|
properties |
if you need to set properties for the Mule application you are deploying, you can use the <properties> top-level element: <properties> <key>value</key> </properties> For example: <properties> <http.url>http://abc.com/employees</http.url> </properties> |
region |
Region of workers cloud. The default value is us-east-1. |
Worker Size
- MICRO (default; 0.1 vCores)
- SMALL (0.2 vCores)
- MEDIUM (1 vCore )
- LARGE (2 vCores)
- XLARGE (4 vCores)
- XXLARGE (8 vCores)
- 4XLARGE (16 vCores)
Worker Region
- us-east-1 (default; US East, N. Virginia)
- us-east-2 (US East, Ohio)
- us-west-1 (US West, N. California)
- us-west-2 (US West, Oregon)
- eu-central-1 (EU, Frankfurt)
- eu-west-1 (EU, Ireland)
- eu-west-2 (EU, London)
- ap-southeast-1 (Asia Pacific, Singapore)
- ap-southeast-2 (Asia Pacific, Sydney)
- ap-northeast-1 (Asia Pacific, Tokyo)
- ca-central-1 (Canada, Central)
- sa-east-1 (South America, São Paulo)
For deploying applications to CloudHub using Mule Maven Plugin, you need a configuration in POM.xml as shown below:
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>3.3.5</version>
<extensions>true</extensions>
<configuration>
<cloudHubDeployment>
<username>Anypoint Username</username>
<p>Anypoint Password</password>
<workers>1</workers>
<workerType>Micro</workerType>
<environment>Sandbox</environment>
<muleVersion>4.2.2</muleVersion>
<applicationName>Demo-Application</applicationName>
</cloudHubDeployment>
</configuration>
</plugin>
Related tutorial: How to Publish Maven Artifacts to Nexus OSS
To deploy applications to CloudHub, you need to execute the below command:
mvn package deploy -DmuleDeploy
Currently, in the above configuration, we have hard coded all the values for the parameter. Instead of passing hard coded values, we can define properties for each parameter and pass properties values through a maven command as shown below:
xxxxxxxxxx
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>3.3.5</version>
<extensions>true</extensions>
<configuration>
<cloudHubDeployment>
<username>${username}</username>
<p>${password}</password>
<workers>${workers}</workers>
<workerType>${worker.type}</workerType>
<environment>${environment}</environment>
<muleVersion>${mule.version}</muleVersion>
<applicationName>${application.name}</applicationName>
</cloudHubDeployment>
</configuration>
</plugin>
To deploy an application to CloudHub, you need to execute the below command:
mvn package deploy -DmuleDeploy -Dusername=AnypointUsername -Dpassword=AnypointPassword -Dworkers=1 -Dworker.type=Micro -Denvironment=Sandbox -Dmule.version=4.2.2
You can see some issues that we are passing password in cleartext, and it is not recommended to store your password in cleartext. Please go through the below video; it will explain how to encrypt your Anypoint Platform password in POM with Maven to deploy an application into CloudHub.
Also, please watch the video below titled, “Deploying Mulesoft Application to Cloudhub using Mule Maven Plugin”
Deploying Mulesoft Application to On-Premises (Standalone) Using Mule Maven Plugin
Mule Maven Plugin has the capability of deploying applications to on-premise MuleSoft runtime. We need to understand some Mule Maven Plugin parameters required for deploying application to MuleSoft runtime.
Parameter |
Description |
muleVersion |
The Mule version running in your local machine instance. If this value does not match the Mule version running in your deployment target, the plugin raises an exception. |
muleHome |
The location of the Mule instance in your local machine. |
For deploying applications to on-premises, you need to do below configuration in POM.xml.
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>3.3.5</version>
<extensions>true</extensions>
<configuration>
<standaloneDeployment>
<muleVersion>${mule.version}</muleVersion>
<muleHome>${mule.home}</muleHome>
</standaloneDeployment>
</configuration>
</plugin>
To deploy Application to on-premise, you need to execute the below command:
mvn package deploy -DmuleDeploy -Dmule.version=4.2.2 -Dmule.home=/mule/bin
Conclusion
Mule Maven Plugin is capable of deploying a MuleSoft application into CloudHub, Anypoint Runtime Fabric, Standalone, Server Group, and MuleSoft Cluster.
This is how you can make use of Mule Maven Plugin for deploying applications to CloudHub and on-premise (standalone).
Further Reading
Opinions expressed by DZone contributors are their own.
Comments