The Mule Maven Plugin is a Maven plugin developed by MuleSoft that allows us to manage, package, and deploy Mule applications using the Maven build automation tool. It simplifies the process of automating tasks related to Mule projects, such as building, deploying, and testing applications, by integrating with the Mule Runtime, either locally or remotely.
With this plugin, we can automate the deployment of our Mule apps to the different Mule Target Deployments:
- Mule Standalone
- Cloudhub 1,.0
- Cloudhub 2.0
- Runtime Fabric
In this post, we will see how to use the Mule Maven Plugin to deploy our Mule apps to Cloudhub 1.0. If you’re looking to deploy your apps to a different Target Deployment check out the other posts of this Series:
- How to deploy to a Standalone Runtime with the Mule Maven Plugin
- How to deploy to Cloudhub 2.0 with the Mule Maven Plugin
- How to deploy to Runtime Fabric with the Mule Maven Plugin
Here are the steps to follow for Cloudhub 1.0:
Create a Connected App
Technically speaking, the Mule Maven Plugin can use User Credentials or a Connected app to deploy applications. However, it’s always recommended to use a Connected App, for security reasons. So, the first thing we need is a Connected App for our Maven deployments.So, the first thing we have to do is to create a Connected App in our Anypoint platform.
For that, go to Anypoint > Access Management > Connected Apps and click on Create app
Then, provide a name for your Connected App and choose the App act on its behalf (client credentials) option.
As a best practice, we want to follow the least-privileged principle and grant only the minimum permissions for our Connected App to deploy to Cloudhub 1.0. Click on Add Scopes and add the following ones:
- Under General:
- View Environment
- View Organization
- Under Runtime Manager:
- Cloudhub Organization Admin
- Create Applications
- Delete Applications
- Download Applications
- Manage Application Data
- Read Alerts
- Read Applications
- Read Servers
Click on Save
You should now see our new Connected App in the list with its client id and secret that we will use in the next step.
Update the settings.xml file
To deploy to CH1.0 the Mule Maven Plugin will have to authenticate to the Anypoint Platform. For that, we created the Connected App in the first step of this tutorial. Now we need to add the credentials of that Connected App to our Mule project. There are two ways of providing the Connected App credentials- One would be to add them directly to the pom file of our Mule project, as part of the plugin configuration
- The other one is by adding those credentials to the settings.xml file of the Maven installation
Head over to your laptop or to the server from which you will run the Mule Maven Plugin and open the settings.xml file. It should be located at ~/.m2 (Linux) or C:\Users\[USER]\.m2.
In Maven, credentials for a repository are added as a <server> element. We need to add the following:
<settings>
…
<servers>
…
<server>
<id>anypoint-exchange-v3</id>
<username>~~~Client~~~</username>
<password>{CLIENT_ID}~?~{SECRET}</password>
</server>
…
</servers>
…
</settings>
- ~~~Client~~~ tells Maven these are Connected App credentials
- {CLIENT_ID} and {SECRET} are the client id and secret of our Connected app.
Create a new Mule Project
Let’s create a mule app for this test. Go to Anypoint Studio and create a new Mule Project. Open the POM file and make the following changes:Mule Maven Plugin in your project
Anypoint Studio, by default, adds the Mule Maven Plugin to our POM. Make sure you’ve got it within the plugins and build sections:<build>
<plugins>
…
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
</plugin>
…
</plugins>
…
</build>
<project>
…
<properties>
…
<mule.maven.plugin.version>4.3.0</mule.maven.plugin.version>
…
</properties>
…
</project>
Configure the Mule Maven Plugin
To deploy to CH1.0 the plugin requires a series of parameters to be set. Here’s an example of the configuration of the Mule Maven Plugin:<plugins>
...
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<cloudHubDeployment>
<uri>https://anypoint.mulesoft.com</uri>
<muleVersion>4.8.0:8e</muleVersion>
<applicationName>${project.name}</applicationName>
<businessGroupId>${project.groupId}</businessGroupId>
<server>anypoint-exchange-v3</server>
<environment>Development</environment>
<workers>1</workers>
<workerType>MICRO</workerType>
<region>eu-west-2</region>
<properties></properties>
<objectStoreV2></objectStoreV2>
<persistentQueues></persistentQueues>
</cloudHubDeployment>
</configuration>
</plugin>
...
</pugins>
cloudHubDeployment
- Tells the plugin to deploy to CH1.0uri
- This is the URL of the Control plane. It’s not required. If not set, by default it is https://anypoint.mulesoft.com. If you are using the EU control plane you will have to set it to https://eu.anypoint.mulesoft.commuleVersion
- The Mule runtime version on top of which the app would be deployed. Make sure you use a version supported by Runtime Manager, you can’t choose any version number in here. If not set, the latest Mule runtime version available in Runtime Manager is selected.applicationName
- The display name for the app in Runtime ManagerbusinessGroupId
- The BG Id where you are deploying to. You can take it from the maven coordinates of the project referencing it with ${project.groupId}. This is only required if you’re deploying to a child BG. If you’re deploying to the Master Org you can omit this parameterserver
- This is the authentication for the Mule Maven Plugin. With the server tag, Maven will use the credentials stored in the settings.xml. Make sure the value in this tag corresponds to the id of the server tag in the settings.xml where we configured the credentials of our Connected App.environment
- Specifies the Anypoint Environment for deployment. Be careful, this is case sensitiveworkers
- The number of workers to be provisioned for the app. The default is set to 1.workerType
- The size of the worker(s). The value could be one of the following:MICRO
(0.1 vCores) - This is the defaultSMALL
(0.2 vCores)MEDIUM
(1 vCore )LARGE
(2 vCores)XLARGE
(4 vCores)XXLARGE
(8 vCores)4XLARGE
(16 vCores)region
- Specifies the region in CH1.0 where we will be deploying the app. The value in this tag has to be one of the following, corresponding to the available regions in Mulesoftus-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)us-gov-west-1
(MuleSoft Government Cloud)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)properties
- Properties defined under this element will be visible from the settings of the app in Runtime Manager. To define properties you need to follow the syntax <key>value</key> as in this example
<properties>
<http.port>8081</http.port>
</properties>
objectStoreV2
- With true or false we can enable/disable the Object Store V2 for the app. The default value is truepersistentQueues
With true or false we can enable/disable the persistence for the VM queues
Run the command
Once the plugin is configured we are ready to use it and deploy the app with the maven command:mvn clean deploy -DmuleDeploy
Head over to Anypoint Runtime Manager and verify that your app has been uploaded and it’s up & running.