<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>2.3.2</version>
<extensions>true</extensions>
</plugin>
Mule Maven Plugin 2.3.x
The Mule Maven Plugin allows you to integrate the packaging, testing, and deployment of your Mule applications with your Maven lifecycle. This plugin allows you to deploy your Mule application to different deployment targets such as standalone runtimes, clustered instances, and CloudHub.
The Mule Maven Plugin supports both Community and Enterprise editions.
Prerequisites
This document assumes that you are familiar with Maven, managing pom.xml
files, and working with Maven plugins. (If you are just getting started with Maven, we suggest you follow Maven’s Getting Started tutorial.) Additionally, this document assumes familiarity with developing Mule applications within Maven. For more information about Mule and Maven, see Using Maven with Mule.
Add the Mule Maven Plugin to a Mule Project
To add the Mule Maven Plugin, you need to add its maven dependency to the project:
Enable extensions. If <extensions>true</extensions> is not present, the plugin does not work.
|
From this repository:
<pluginRepositories>
<pluginRepository>
<id>mule-public</id>
<url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
</pluginRepository>
</pluginRepositories>
This enables the Mule Maven Plugin in your project.
Mule Application Packaging
The Mule Maven Plugin can package your Mule application into a deployable ZIP file that you can later deploy to a running Mule Runtime.
-
Make sure you added the Mule Maven Plugin to your
pom.xml
file. -
From the command line in your project’s folder, run the package goal:
$ mvn clean package
The plugin packages your application and creates the deployable ZIP file into the target directory within your project’s folder.
Source Directory Reference
The src
directory has two main folders: main
and test
.
The plugin does not consider any other directory inside src
when packaging the application.
src/main
src/main is the root folder for all the productive source code of the application.
Folder | Folder Type | Description |
---|---|---|
|
source |
The root folder of the Mule configuration files. This folder is mandatory. |
|
resource |
It contains the application resources, such as XML, JSON, and properties files. |
The plugin sends all files inside src/main/app
and src/main/resources
to the root directory of your binary package.
Nested folders within src/main/app
are preserved as directories within the root directory of the binary package.
src/test
src/test is the root folder for all the test source code of the application.
Folder | Folder Type | Description |
---|---|---|
|
source |
It’s the root folder of the test classes used to validate the custom Java code of the app. |
|
source |
It contains the MUnit source code. |
|
resource |
It contains resources, such as XML, JSON, and properties files. |
Including and Excluding Additional Libraries
You can include additional JAR libraries into your project by using the <inclusion>
element. Included libraries will be added to the /lib
folder of your project.
Example XML
<plugin>
...
<configuration>
<inclusions>
<inclusion>
<groupId>com.mulesoft.security</groupId>
<artifactId>mule-module-security-property-placeholder</artifactId>
</inclusion>
</inclusions>
</configuration>
...
</plugin>
This example includes the Security Property Placeholder module into the project’s /lib
directory.
You can also use the <exclusion>
element to exclude libraries from your project’s /lib
folder when packaging the application.
Mule Application Deployment
The Mule Maven Plugin allows you to automate the deployment of your Mule application to your Mule servers.
By default, this plugin allows you to deploy using five different deployment strategies:
-
CloudHub deployment.
Automate the deployment of your Mule Application to CloudHub. -
Runtime Fabric deployment.
Deploy your Mule Application to Runtime Fabric. -
Runtime Manager REST API deployment.
Deploy your Mule Application to your Mule server, or server clusters using the Runtime Manager REST API. -
Mule Agent deployment.
Deploy your Mule Application using the Mule Agent.
This deployment strategy only works if all your Mule instances live under the same address space. -
Standalone runtime deployment.
Deploy to a runtime running on your machine.
When deploying an application using the Mule Maven Plugin you need to specify a valid deployment configuration in your pom.xml
file.
You can set up deployment configurations using their dedicated deployment references.
Deploy a Mule Application to CloudHub
Prerequisites
-
The host and port number of your HTTP Listener flow sources are properly configured.
If you are using the HTTP Listener as sources for your flow, you need to set its host to
0.0.0.0
and its port to${http.port}
.CloudHub then dynamically allocates a port at deployment time.
Deploying to CloudHub
-
Make sure you added the Mule Maven Plugin to your
pom.xml
file. -
Inside the plugin element, add a configuration for your CloudHub deployment as shown below:
<plugin> ... <configuration> <cloudHubDeployment> <uri>https://anypoint.mulesoft.com</uri> <muleVersion>${mule.version}</muleVersion> <username>${username}</username> <password>${password}</password> <applicationName>${cloudhub.application.name}</applicationName> <environment>${environment}</environment> <properties> <key>value</key> </properties> </cloudHubDeployment> </configuration> </plugin>
The example is using placeholder values. Configure each value with your CloudHub information.
-
From the command line in your project’s folder, package the app and run the deploy goal:
$ mvn clean package deploy -DmuleDeploy
Redeploying to CloudHub
To redeploy the app, run the same command as you did to deploy.
CloudHub rewrites the app you had deployed.
Undeploying from CloudHub
To undeploy an app, run the following command:
$ mvn mule:undeploy
The undeploy command also deletes the app in Mule Maven Plugin 2.3.3 and later versions.
CloudHub Deployment Reference
Parameter | Description |
---|---|
|
Top-Level Element. |
|
Your Anypoint Platform URI. |
|
The Mule runtime engine version that will run in your CloudHub instance. |
|
Your CloudHub username. |
|
Your CloudHub password. |
|
The name of your application in CloudHub. |
|
Boolean value. When set to true, skips the plugin deployment goal. Its default value is false. |
|
Absolute file location of the ZIP to be deployed. |
|
The CloudHub environment to which you want to deploy. |
|
Top-Level element. <properties> For example: <properties> |
|
The number of workers. |
|
Size of each worker. Accepted values are: MICRO (0.1 vCores) The default value is MICRO. |
|
Region of worker clouds. Accepted values are:
The default value is us-east-1. |
|
Business group of the deployment. |
|
The Business group id of the deployment. |
|
Maven server with Anypoint Platform credentials. This is only needed if you want to use your credentials stored in your Maven |
|
The allowed elapsed time, in milliseconds, between the start of the deployment process and the confirmation that the artifact has been deployed. The default value is |
|
This feature is available in plugin version 2.3.2 and later. |
|
Boolean value. When set to true, skips the plugin deployment goal. Its default value is false. |
Deploy a Mule Application to Runtime Fabric
Prerequisites
-
Before deploying an application to Runtime Fabric, check the number of resources required. See Allocating Resource for Application Deployment on Runtime Fabric for more information.
-
The application must be published in Exchange.
-
To do this from Studio, see Publishing a Project to Exchange.
-
To do this using Maven, see Publish and Deploy Exchange Assets Using Maven.
-
Studio allows you to select only two project types when uploading an application to Exchange: example and template . To specify a different project type, publish your application using Maven.
|
Deploying to Runtime Fabric
-
Make sure you added the Mule Maven Plugin to your
pom.xml
file. -
Inside the plugin element, add a configuration for your Runtime Fabric deployment as shown below:
<plugin> ... <configuration> <runtimeFabricDeployment> <uri>https://anypoint.mulesoft.com</uri> <muleVersion>3.9.4</muleVersion> <username>user</username> <password>pass</password> <applicationName>newapp</applicationName> <target>rtf</target> <environment>Sandbox</environment> <provider>MC</provider> <replicas>1</replicas> <properties> <key>value</key> </properties> <deploymentSettings> <enforceDeployingReplicasAcrossNodes>false</enforceDeployingReplicasAcrossNodes> <updateStrategy>recreate</updateStrategy> <clustered>false</clustered> <forwardSslSession>false</forwardSslSession> <lastMileSecurity>false</lastMileSecurity> <resources> <cpu> <reserved>20m</reserved> <limit>1500m</limit> </cpu> <memory> <reserved>700Mi</reserved> <limit>800Mi</limit> </memory> </resources> <http> <inbound> <publicUrl>url</publicUrl> </inbound> </http> </deploymentSettings> </runtimeFabricDeployment> </configuration> </plugin>
The example is using placeholder values. Configure each value with your Runtime Fabric information.
-
From the command line in your project’s folder, package the application and run the deploy goal:
$ mvn clean package deploy -DmuleDeploy
Redeploying to Runtime Fabric
To redeploy the application, run the same command as you did to deploy.
Runtime Fabric rewrites the application you had deployed.
Runtime Fabric Deployment Reference
Parameter | Description |
---|---|
|
Top-Level Element. |
|
Your Anypoint Platform URI. |
|
The Mule runtime engine version that will run in your Runtime Fabric instance. |
|
Your Anypoint Platform username. |
|
Your Anypoint Platform password. |
|
The name of your application deployed in Exchange. |
|
The Runtime Fabric target name where to deploy the app. |
|
Provider type. Set to MC ("MC" specifies Runtime Fabric). |
|
The Anypoint Platform environment to which you want to deploy. |
|
Specifies the number of replicas, or instances, of the Mule application to deploy |
|
The Business group path of the deployment.
|
|
The Business group id of the deployment. |
|
The allowed elapsed time, in milliseconds, between the start of the deployment process and the confirmation that the artifact has been deployed. |
|
Maven server with Anypoint Platform credentials. This is only needed if you want to use your credentials stored in your Maven |
|
Top-Level element.
For example:
|
|
Boolean value. When set to true, skips the plugin deployment goal. Its default value is false. |
|
See the deploymentSettings Reference table below for a complete list of parameters that can be configured inside this element. |
deploymentSettings Reference
The deployment configuration for Runtime Fabric has changed in Mule Maven Plugin 2.3.5. If you are using an earlier version, see Mule Maven Plugin 2.3.5 Release Notes for a list of changed properties.
Parameter | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Enforces the deployment of replicas across different nodes. The default value is Configuration example:
|
||||||||||
|
The default value is Configuration example:
|
||||||||||
|
Enables SSL forwarding during a session. The default value is Configuration example:
|
||||||||||
|
Enables clustering across two or more replicas of the application. The default value is Configuration example:
|
||||||||||
|
Enable Last-Mile security to forward HTTPS connections to be decrypted by this application
|
||||||||||
|
Configuration example:
|
||||||||||
|
Configuration example:
|
Deploy a Mule Application to a Standalone Mule Runtime
-
Make sure you added the Mule Maven Plugin to your
pom.xml
file. -
Inside the plugin element, add a configuration for your CloudHub deployment as shown below:
<plugin> ... <configuration> <standaloneDeployment> <muleHome>${mule.home.test}</muleHome> <muleVersion>${mule.version}</muleVersion> </standaloneDeployment> </configuration> </plugin>
The example is using placeholder values. Configure each value with your local Mule runtime engine information.
-
From the command line in your project’s folder, package the application and run the deploy goal:
$ mvn clean package deploy -DmuleDeploy
Standalone Deployment Reference
Parameter | Description |
---|---|
|
Top-Level Element. |
|
The Mule runtime engine version running in your local machine instance. The Mule Maven Plugin does not download a Mule runtime engine if these values don’t match. |
|
The location of the Mule instance in your local machine. |
|
The allowed elapsed time, in milliseconds, between the instant when the deployable is copied to the runtime and the creation of the respective anchor file. |
|
Boolean value. When set to true, skips the plugin deployment goal. Its default value is false.
The default value is |
Deploy a Mule Application Using the Runtime Manager REST API
Prerequisites
-
You need a server, server group or cluster created in Runtime Manager.
-
To create a server, see Creating a Server.
-
To create a server group, see Creating a Server Group.
-
To create a cluster, see Creating a Cluster.
-
Deploying Using the Runtime Manager REST API
-
Make sure you added the Mule Maven Plugin to your
pom.xml
file. -
Inside the plugin element, add a configuration for your Runtime Manager deployment as shown below:
<plugin> ... <configuration> <armDeployment> <uri>https://anypoint.mulesoft.com</uri> <target>${target}</target> <targetType>${target.type}</targetType> <username>${username}</username> <password>${password}</password> <environment>${environment}</environment> <properties> <key>value</key> </properties> </armDeployment> </configuration> </plugin>
The example is using placeholder values. Configure each value with your Runtime Manager information.
-
From the command line in your project’s folder, package the application and run the deploy goal:
$ mvn clean package deploy -DmuleDeploy
Runtime Manager REST API Deployment Reference
Parameter | Description |
---|---|
|
Top-Level Element. |
|
The runtime version required for your application to run in your deployment target. The Mule Maven Plugin does not download a Mule runtime engine if these values don’t match. |
|
The allowed elapsed time, in milliseconds, between the start of the deployment process and the confirmation that the artifact has been deployed. The default value is |
|
The server URI where your Mule instances are installed. |
|
The server name for the server where your Mule instances are installed. |
|
The type of target to which you are deploying. Valid values are:
|
|
Your username for the server where your Mule instances are installed. |
|
Your password for the server where your Mule instances are installed. |
|
The environment name for the server where your Mule instances are installed. |
|
The Business group path of the deployment. |
|
The Business group id of the deployment. |
|
Maven server with Anypoint Platform credentials. This is only needed if you want to use your credentials stored in your Maven settings.xml file. This is not the Mule server name. |
|
Top-Level element. <properties> For example: <properties> |
|
Boolean value. When set to true, the plugin does not validate certificates for the configured server. |
|
Boolean value. When set to true, skips the plugin deployment goal. Its default value is false. |
|
This feature is available in plugin version 2.3.2 and later. |
Deploy a Mule Application Using the Mule Agent
-
Make sure you added the Mule Maven Plugin to your
pom.xml
file. -
Inside the plugin element, add a configuration for your Mule Agent deployment as shown below:
<plugin> ... <configuration> <agentDeployment> <uri>http://localhost:9999/</uri> </agentDeployment> </configuration> </plugin>
The example is using placeholder values. Configure the URI value with your remote server information.
-
From the command line in your project’s folder, package the application and run the deploy goal:
$ mvn clean package deploy -DmuleDeploy
Mule Agent Deployment Reference
Parameter | Description |
---|---|
|
Top-Level Element. |
|
The runtime version required for your application to run in your deployment target. The Mule Maven Plugin does not download a Mule runtime engine if these values don’t match. |
|
The allowed elapsed time, in milliseconds, between the start of the deployment process and the confirmation that the artifact has been deployed. The default value is |
|
The server URI where your Mule instances are installed. |
|
Boolean value. When set to true, skips the plugin deployment goal. Its default value is false. |
Encrypting credentials
Encrypted credentials are available in all platform deployments: CloudHub, Runtime Fabric, and Runtime Manager.
To use encrypted credentials when deploying, you need to set up your Maven main encrypted password and your settings-security.xml
file.
-
Create a main password for your Maven configuration.
$ mvn --encrypt-main-password <yourMainPassword>
Maven returns your main password encrypted:
{l9vZ2uM5SdgHy+H12z4pX7LEOZn3Kbnqmt3kIquLjnQ=}
-
Create a
settings-security.xml
file in your~/.m2
repository, and add your encrypted main password.<settingsSecurity> <main>{l9vZ2uM5SdgHy+H12z4pX7LEOZn3Kbnqmt3kIquLjnQ=}</main> </settingsSecurity>
-
Encrypt your Anypoint platform password:
$ mvn --encrypt-password <yourAnypointPlatformPassword>
Maven returns your Anypoint platform password encrypted:
{HTWFGH5BG9QmvJ1B=}
-
Add your encrypted Anypoint Platform password to your
settings.xml
file in the<server>
element:<settings> ... <servers> ... <server> <id>my.anypoint.credentials</id> <username>my.anypoint.username</username> <password>{HTWFGH5BG9QmvJ1B=}</password> </server> ... </servers> ... </settings>
-
In your configuration deployment, reference the credentials injecting the server id configured in your
settings.xml
file. Below is an example of a CloudHub Deployment using encrypted credentials:
<plugin>
...
<configuration>
<cloudHubDeployment>
<uri>https://anypoint.mulesoft.com</uri>
<muleVersion>${mule.version}</muleVersion>
<server>my.anypoint.credentials</server>
<applicationName>${cloudhub.application.name}</applicationName>
<environment>${environment}</environment>
<properties>
<key>value</key>
</properties>
</cloudHubDeployment>
</configuration>
</plugin>
Make sure that username and password are not set in the deployment configuration, as they have precedence over the defined server id. |
Skipping Plugin Execution
You can skip the plugin execution by setting the skip
flag to true inside your deployment configuration:
<plugin>
...
<configuration>
<standaloneDeployment>
<muleHome>${mule.home.test}</muleHome>
<skip>true</skip>
</standaloneDeployment>
</configuration>
</plugin>
Skipping Deployment Verification
You can skip the status verification of your deployed app by setting the skipDeploymentVerification
flag to true inside of any of the platform deployments (Cloudhub, Runtime Manager, and Runtime Fabric):
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<runtimeFabricDeployment>
...
<skipDeploymentVerification>true</skipDeploymentVerification>
...
</runtimeFabricDeployment>
</configuration>
</plugin>
If the skipDeploymentVerification
flag is not present, the default value is false.
This feature is available in plugin version 2.3.2 and later.
Anypoint Runtime Manager On-Premises TLS Errors
When trying to connect to an instance of Runtime Manager that’s on an Anypoint Platform Private Cloud Edition installation, the plugin validates certificates for that server. If you haven’t installed the server certificates in your truststore, an SSL error occurs. To avoid this problem you can run the plugin in an insecure mode, which skips the security validations. You can use the armInsecure
tag or the arm.insecure
system property.
Enabling an insecure connection is a dangerous practice. Don’t use this unless you know what you are doing and your On-Premises installation is isolated in a local network. |
See the configuration example below:
<plugin>
...
<configuration>
<armDeployment>
<target>${target}</target>
<targetType>${target.type}</targetType>
<username>${username}</username>
<password>${password}</password>
<environment>${environment}</environment>
<armInsecure>true</armInsecure>
</armDeployment>
</configuration>
</plugin>