How to deploy to a Standalone Runtime with the Mule Maven Plugin


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 a Standalone Mule Runtime. 

If you’re looking to deploy your apps to a different Target Deployment check out the other posts of this Series:

For the Standalone target deployment, we can use three different configurations of the Mule Maven Plugin:
  • Deployment to a local runtime - in this case, the Maven installation is running locally to the Standalone runtime
  • Deployment using the Runtime Manager Agent
  • Deployment using the Runtime Manager REST API - This allows us to deploy an app remotely by interacting with the control plane. This is the method we’ll see in this post. Here are the steps to follow:

Prerequisites

To follow this tutorial we need a Standalone Mule runtime installed. If you don’t have one you can quickly spin up one by following the steps in one of these steps:


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 to create a Connected App for our Maven deployments. 

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 Standalone Runtime. Click on Add Scopes and add the following ones:
  • Under Runtime Manager:
    • Create Applications
    • Delete Applications
    • Manage Application Data
    • Read Applications
    • Read Servers
Select the Business Groups and the Environments on which you are planning to deploy with the Mule Maven plugin


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 a Standalone Runtime the Mule Maven Plugin will have to authenticate to the Anypoint Platform, as it will go through the Runtime Manager REST API. For that, we created the Connected App in the previous step. 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
In this tutorial, we’ll go for the second option. This way credentials are not included in the code of our Mule app.

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>

Where:

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

Update the version of the Mule Maven Plugin in the properties section. In this tutorial, we will use version 4.3.0 of the plugin

<project>

<properties>

<mule.maven.plugin.version>4.3.0</mule.maven.plugin.version>

</properties>

</project>


Configure the Mule Maven Plugin

To deploy to a Standalone Runtime via the Runtime Manager REST API, the plugin requires a series of parameters to be set. Here’s an example of the configuration of the Mule Maven Plugin:

<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<armDeployment>
<applicationName>${project.name}</applicationName>
<muleVersion>${app.runtime}</muleVersion>
<uri>https://anypoint.mulesoft.com</uri>
<target>[YOUR_MULE_SERVER]</target>
<targetType>server</targetType>
<server>anypoint-exchange-v3</server>
<businessGroupId>${project.groupId}</businessGroupId>
<environment>Development</environment>
<properties>
<key>value</key>
</properties>
</armDeployment>
</configuration>
</plugin>

Where:

  • armDeployment - Tells the plugin to deploy to a Standalone Runtime
  • applicationName - The display name for the app in Runtime Manager
  • muleVersion - The Mule runtime version required for the application. Notice that in the Standalone Model, the runtime is already installed, so the version you put in this tag needs to match the version of the runtime in the deployment target. If not, the plugin will raise an exception.
  • target - The name of the Server/ServerGroup/Cluster where you’ll be deploying the app
  • targetType - They type of Standalone Target. Values can be
    • server
    • serverGroup
    • cluster
  • server - This is the authentication for the Mule Maven Plugin. This is not the name of the Mule Server where you installed the runtime. 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.
  • businessGroupId - 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 parameter
  • environment - Specifies the Anypoint Environment for deployment. Be careful, this is case sensitive
  • 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>


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.


You can also verify, from your Mule Standalone Server that there’s a new app under the $MULE_HOME/apps directory



Previous Post Next Post