{{announcement.body}}
{{announcement.title}}

Mule Maven Plugin for Deploying MuleSoft Applications

DZone 's Guide to

Mule Maven Plugin for Deploying MuleSoft Applications

In this article take a look at Mule Maven Plugin for deploying MuleSoft applications.

· Integration Zone ·
Free Resource

Mule standing outside

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

XML
xxxxxxxxxx
1
 
1
<p>
2
<groupId>org.mule.tools.maven</groupId>
3
<artifactId>mule-maven-plugin</artifactId>
4
<version>3.3.5</version>
5
</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.

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:

XML
xxxxxxxxxx
1
17
 
1
<p>
2
   <groupId>org.mule.tools.maven</groupId>
3
   <artifactId>mule-maven-plugin</artifactId>
4
   <version>3.3.5</version>
5
   <extensions>true</extensions>
6
   <configuration>
7
      <cloudHubDeployment>
8
         <username>Anypoint Username</username>
9
         <p>Anypoint Password</password>         
10
         <workers>1</workers>
11
         <workerType>Micro</workerType>
12
         <environment>Sandbox</environment>
13
         <muleVersion>4.2.2</muleVersion>
14
         <applicationName>Demo-Application</applicationName>
15
      </cloudHubDeployment>
16
   </configuration>
17
</plugin>


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:     

XML
xxxxxxxxxx
1
17
 
1
<p>
2
   <groupId>org.mule.tools.maven</groupId>
3
   <artifactId>mule-maven-plugin</artifactId>
4
   <version>3.3.5</version>
5
   <extensions>true</extensions>
6
   <configuration>
7
      <cloudHubDeployment>
8
         <username>${username}</username>
9
         <p>${password}</password>         
10
         <workers>${workers}</workers>
11
         <workerType>${worker.type}</workerType>
12
         <environment>${environment}</environment>
13
         <muleVersion>${mule.version}</muleVersion>
14
         <applicationName>${application.name}</applicationName>
15
      </cloudHubDeployment>
16
   </configuration>
17
</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.

XML
xxxxxxxxxx
1
12
 
1
<p>
2
   <groupId>org.mule.tools.maven</groupId>
3
   <artifactId>mule-maven-plugin</artifactId>
4
   <version>3.3.5</version>
5
   <extensions>true</extensions>
6
   <configuration>
7
      <standaloneDeployment>
8
         <muleVersion>${mule.version}</muleVersion>
9
         <muleHome>${mule.home}</muleHome>        
10
      </standaloneDeployment>
11
   </configuration>
12
</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

Mule Maven Plugin for CloudHub Deployment

Set Up Anypoint Studio: All You Need to Know

Topics:
mulesoft ,integration ,tutorial ,mule maven plugin ,anypoint platform ,anypoint runtime fabric

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}