Contact Us 1-800-596-4880

Mule ESB Plugin For Maven

Mule Runtime Engine versions 3.5, 3.6, and 3.7 reached End of Life on or before January 25, 2020. For more information, contact your Customer Success Manager to determine how you can migrate to the latest Mule version.
As of September 2015, the muleesb-maven-plugin is deprecated and replaced by the mule-maven-plugin, which provides new features and functionality. For details, see Mule Maven Plugin.

The muleesb-maven-plugin allows you to control Mule ESB instances from within a Maven environment. It is part of the framework for developing Mule applications with Maven, an overview of which you can find in Using Maven with Mule. The plugin allows you to:

  • Deploy a Mule application to a local standalone server

  • Run integration tests in a local standalone deployment

  • Start, stop, and restart a local standalone server

  • Run integration tests in a local cluster deployment

The plugin supports both the 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.

Adding the Plugin

The following sections explain how to add the Mule plugin for Maven.

Adding the Maven Dependency for the Plugin

Edit your settings.xml or project file to include the following:

<plugin>
  <groupId>org.mule.tools</groupId>
  <artifactId>muleesb-maven-plugin</artifactId>
  <version>1.0</version>
</plugin>

Adding the Maven Repository

The repository for the plugin is located at https://repository.mulesoft.org/nexus/content/repositories/releases/. To add it to your Maven installation, edit your settings.xml or project file to include the following:

<pluginRepositories>
    <pluginRepository>
        <id>mule-ee-public</id>
        <url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

You can also find the plugin .jar and POM files manually at the online repository for the plugin.

A Simple Example

This section describes the simplest use for the plugin. In this scenario, you have Mule ESB already installed and a Mule application already built. The configuration listed below causes the plugin to run during the pre-integration-test phase and perform the following actions:

  • Deploy the application to the configured Mule server

  • Start Mule ESB if it is not running

...
<plugins>
    <plugin>
        <groupId>org.mule.tools</groupId>
        <artifactId>muleesb-maven-plugin</artifactId>
        <version>1.0</version>
        <configuration>
            <muleHome>${mule.home}</muleHome>
            <applications>
                <application>${app.location}</application>
            </applications>
        </configuration>
        <executions>
            <execution>
                <id>deploy</id>
                <goals>
                    <goal>start</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>
...

In the above example, mule.home is the full path for a local Mule standalone installation, and app.location is the full path for a Mule application.

For the above example to work, you need to have the Mule ESB repository defined in your settings.xml or your pom.xml. For details, see Using Maven with Mule and Configuring Maven to Work with Mule ESB.

Defining Mule ESB as a Maven Dependency

Instead of using an existing Mule ESB server, you can make the plugin download and install Mule ESB standalone from a Maven repository. To do so, configure the plugin as shown below.

...
<plugin>
    <groupId>org.mule.tools</groupId>
    <artifactId>muleesb-maven-plugin</artifactId>
    <configuration>
        <muleDistribution>
            <groupId>com.mulesoft.muleesb.distributions</groupId>
            <artifactId>mule-ee-distribution-standalone</artifactId>
            <version>${mule.version}</version>
            <type>tar.gz</type>
        </muleDistribution>
        <applications>
            <application>${app.1.location}</application>
            <application>${app.2.location}</application>
        </applications>
    </configuration>
</plugin>
...

Instead of specifying the full Maven coordinates as shown above, you can leave out groupId and artifactId and define only the Mule version. This way the plugin will use the official MuleSoft group and artifact IDs for the CE or EE versions. This configuration is shown below:

...
<plugin>
    <groupId>org.mule.tools</groupId>
    <artifactId>muleesb-maven-plugin</artifactId>
    <configuration>
        <muleVersion>3.7.0</muleVersion>
        <applications>
...

Running Integration Tests

One of the most important uses for the plugin is to run integration tests on your integration application. The plugin includes a complete working example in src/it/example-integration-tests.

The working example POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.mule.tools.muleesb.it</groupId>
    <artifactId>example-deploy-test</artifactId>
    <version>1.0</version>
    <packaging>mule</packaging>

    <description>Using the plugin for integration tests</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.mule.tools</groupId>
                <artifactId>maven-mule-plugin</artifactId>
                <version>1.7</version>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>@project.groupId@</groupId>
                <artifactId>@project.artifactId@</artifactId>
                <version>@project.version@</version>
                <configuration>
                    <arguments>
                        <argument>-M-Dhttp.port=${http.port}</argument>
                    </arguments>
                    <muleVersion>${mule.version}</muleVersion>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.16</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

To package, test, and deploy your project to Mule ESB:

  • Pack your project in the Mule application format using maven-mule-plugin

  • Run integration tests and report using maven-failsafe-plugin

  • Deploy the packaged application to a new Mule ESB downloaded from a Maven repository, using mulees-maven-plugin

In this scenario, you can only specify the Mule version and the parameters for Mule Standalone. The plugin downloads the default version of Mule ESB Enterprise Edition from a configured Maven repository, unpacks it, and deploys the packaged application from your project. By default, the goals to be executed are pre-integration-test and post-integration-test.

Below is example code showing how to configure the maven-failsafe-plugin so that, when you run mvn verify, it stops Mule Standalone during the post-integration-test phase.

The example code:

<plugin>
    <groupId>@project.groupId@</groupId>
    <artifactId>@project.artifactId@</artifactId>
    <version>@project.version@</version>
    <configuration>
        <arguments>
            <argument>-M-Dhttp.port=${http.port}</argument>
        </arguments>
        <muleVersion>${mule.version}</muleVersion>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>deploy</goal>
            </goals>
        </execution>
        <execution>
            <id>stop</id>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Full Example

This example, the plugin works with an external Mule standalone deployment, and performs the following actions:

  • Configure two applications to be deployed:

    <applications>
       <application>/home/mule/apps/sampleApp1</application>
       <application>/home/mule/apps/sampleApp2</application>
    </applications>
  • Adds two external libraries to the server:

    <libs>
       <lib>/home/mule/libs/activemq-all-5.5.0.jar</lib>
       <lib>/home/mule/libs/activemq-core.jar</lib>
    </libs>
  • Adds a domain to be deployed:

    <domain>/home/mule/mvn/thisproject/domain</domain>
  • Specifies a script to run before starting the Mule server

    <script>/home/mule/mvn/thisproject/script.groovy</script>

The full code:

...
<plugin>
    <groupId>org.mule.tools</groupId>
    <artifactId>muleesb-maven-plugin</artifactId>
    <configuration>
        <muleHome>/home/mule/mule-standalone-3.7.0</muleHome>                 <!-- (1) -->
        <applications>
            <application>/home/mule/apps/sampleApp1</application>
            <application>/home/mule/apps/sampleApp2</application>  <!-- (2) -->
        </applications>
        <libs>
          <lib>/home/mule/libs/activemq-all-5.5.0.jar</lib>
          <lib>/home/mule/libs/activemq-core.jar</lib>         <!-- (3) -->
        </libs>
        <arguments>
            <argument>-M-Dport.1=1337</argument>
            <argument>-M-Dport.2=1338</argument>          <!-- (4) -->
        </arguments>
        <domain>/home/mule/mvn/thisproject/domain</domain>        <!-- (5) -->
        <script>/home/mule/mvn/thisproject/script.groovy</script>         <!-- (6) -->
    </configuration>
    <executions>
        <execution>
            <id>deploy</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>deploy</goal>                       <!-- (7) -->
            </goals>
        </execution>
        <execution>
            <id>stop</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>                         <!-- (8) -->
            </goals>
        </execution>
    </executions>
</plugin>
...

Comments reference:

No. Description Notes

1

Sets your Mule root folder, in this case /home/mule/mule-standalone-3.7.0.

2

These two child elements define the Mule applications that will be deployed to the Mule instance. Applications defined with this parameter can be either a deployable Mule application zip file or an exploded Mule application folder

Optional

3

External libraries to add to Mule standalone

Optional

4

Arguments for the Mule server

Optional

5

Domain to deploy. To add the application to the domain, you must configure the application manually

Optional

6

Groovy script to execute just before the first execution of the plugin

Optional

7

Execution goal. Use the start goal to start the Mule instance in the desired phase.

8

Execution goal. Use the stop goal to stop the Mule instance in the desired phase.

Deploying to a Mule Cluster

Using a similar configuration to the one detailed in the previous section, you can use the plugin to work with a Mule cluster. The plugin will create the cluster for you with the number of nodes that you specify.

<plugin>
    <groupId>org.mule.tools</groupId>
    <artifactId>muleesb-maven-plugin</artifactId>
    <configuration>
        <muleDistribution>
            <groupId>com.mulesoft.muleesb.distributions</groupId>
            <artifactId>mule-ee-distribution-standalone</artifactId>
            <version>3.5.0</version>           <!-- (1) -->
            <type>tar.gz</type>
        </muleDistribution>
        <clusterSize>2</clusterSize>                     <!-- (2) -->
        <applications>
            <application>/home/mule/apps/sampleApp1</application>
            <application>/home/mule/apps/sampleApp2</application>
        </applications>
        <libs>
          <lib>/home/mule/libs/activemq-all-5.5.0.jar</lib>
          <lib>/home/mule/libs/activemq-core.jar</lib>
        </libs>
        <arguments>
            <argument>-M-Dport.1=1337</argument>
            <argument>-M-Dport.2=1338</argument>
        </arguments>
    </configuration>
    <executions>
        <execution>
            <id>clusterDeploy</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>clusterDeploy</goal>                <!-- (3) -->
            </goals>
        </execution>
        <execution>
            <id>clusterStop</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>clusterStop</goal>                  <!-- (4) -->
            </goals>
        </execution>
    </executions>
</plugin>
No. Description Notes

1

Mule ESB version to use.

2

Number of nodes to make up the cluster.

3

Execution goal. To start the cluster, use the clusterDeploy goal.

4

Execution goal. To stop the cluster, use the clusterStop goal.

Skipping Plugin Execution

When set to true, the skip parameter causes plugin execution to be skipped. This parameter works with all plugin goals. It is most commonly set to skipTests, to avoid having to prepare your test infrastructure if you don’t want your tests to run.

<plugin>
    <groupId>org.mule.tools</groupId>
    <artifactId>muleesb-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>deploy</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>deploy</goal>
            </goals>
            <configuration>
                <muleHome>/home/mule/mule-standalone-3.5.0</muleHome>
                <skip>${skipTests}</skip>
            </configuration>
        </execution>
    </executions>
</plugin>

See Also