Contact Us 1-800-596-4880

Mule Maven Plugin

This version of Mule reached its End of Life on May 2, 2023, when Extended Support ended.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

Mule Maven plugin versions 3.0.0, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.1.5, 3.1.6, and 3.1.7 are deprecated.

The Mule Maven plugin enables you to integrate the packaging and deployment of your Mule applications with your Maven lifecycle.
See Package a Mule Application for packaging instructions.

The Mule Maven plugin is compatible with Mule runtime engine (Enterprise Edition) and with Mule Kernel (Community Edition).

Using the Mule Maven plugin, you can automate your Mule application deployment to CloudHub, to Anypoint Runtime Fabric, or on-premises, using any of the following deployment strategies:

Compatibility

  • Mule 4.x

  • Anypoint Studio 7.x

Mule Maven Plugin Goals

The Mule Maven plugin has three goals:

  • package
    Generates the jar file for your project.

  • deploy
    Automatically uploads and starts your application in any of the application deployment targets (CloudHub, Runtime Fabric, or On-Premises).

  • mule:undeploy
    Automatically removes your application from any of the application deployment targets (CloudHub, Runtime Fabric, or On-Premises).

Each goal accepts parameters that are unique to the desired plugin behavior. To provide a parameter from the command line, prepend -D to the parameter name.

Package Goal

The package goal generates the application JAR file. This goal binds by default to the Maven lifecycle phase: package.

Optional Parameters

Name Type Description

onlyMuleSources

boolean

Generates the application JAR file containing only the source code. This property is just for sharing purposes.

attachMuleSources

boolean

Attaches the source code inside the generated JAR file.

lightweightPackage

boolean

Doesn’t generate the repository with all the application dependencies inside the JAR file. This property is just for sharing purposes.

For example, to execute the package goal and set the attachMuleSources parameter, you run the following command:

mvn package -DattachMuleSources

Deploy Goal

This goal uploads and deploys the application JAR file to any of the application deployment targets. The deploy goal binds by default to the Maven lifecycle phase: deploy.

Optional Parameters

Name Type Description

artifact

String

Path to the application JAR file to be deployed. By default is set to the application target folder.

muleDeploy

boolean

Instructs the plugin to deploy using the deployment strategy defined in the plugin configuration. If the muleDeploy parameter is not set, the plugin uploads the artifacts to the repository defined in the distributionManagement section of the application’s pom.xml file.

For example, to execute the deploy goal and set the muleDeploy parameter, you run the following command:

mvn deploy -DmuleDeploy

Undeploy Goal

This goal removes an application from any of the application deployment targets. It uses the information from the plugin configuration to remove the application from the defined deployment target.

To execute the undeploy goal, run the following command:

mvn mule:undeploy

The undeploy goal also deletes the app in Mule Maven plugin 3.3.0 and later versions.

Add the Mule Maven Plugin to a Mule Project

Before you can perform any operations, you must add the Mule Maven plugin to your project.

To add the Mule Maven plugin, you need to add its maven dependency to the project:

<plugin>
  <groupId>org.mule.tools.maven</groupId>
  <artifactId>mule-maven-plugin</artifactId>
  <version>3.7.1</version>
  <extensions>true</extensions>
</plugin>

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.

If <extensions>true</extensions> is not present, the plugin does not work.

Skip Plugin Execution

You can skip the plugin execution by setting the skip parameter to true inside your deployment configuration:

<plugin>
  <groupId>org.mule.tools.maven</groupId>
  <artifactId>mule-maven-plugin</artifactId>
  <version>3.7.1</version>
  <extensions>true</extensions>
  <configuration>
    <standaloneDeployment>
      <muleHome>${mule.home.test}</muleHome>
      <skip>true</skip>
    </standaloneDeployment>
  </configuration>
</plugin>

Skip Deployment Verification

You can skip the status verification of your deployed app by setting the skipDeploymentVerification parameter 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>3.7.1</version>
  <extensions>true</extensions>
  <configuration>
    <runtimeFabricDeployment>
      ...
      <skipDeploymentVerification>true</skipDeploymentVerification>
      ...
    </runtimeFabricDeployment>
  </configuration>
</plugin>

If the skipDeploymentVerification parameter is not present, the default value is false.
This feature is available in plugin version 3.2.5 and later.

Configure Shared Libraries

Configure shared libraries when you need to make an application’s dependency visible to your application’s connectors. To configure a dependency as a shared library, add the following elements in your Mule Maven plugin configuration inside your project’s pom.xml file:

<sharedLibraries>
  <sharedLibrary>
    <groupId>${dependencyGroupID}</groupId>
    <artifactId>${dependencyArtifactID}</artifactId>
  </sharedLibrary>
</sharedLibraries>

The following example configures Anypoint Connector for Database (Database Connector) in a project, and also configures the MySQL driver as a shared library:

<build>
  <plugins>
    <!-- Mule Maven Plugin configuration -->
    <plugin>
    	<groupId>org.mule.tools.maven</groupId>
    	<artifactId>mule-maven-plugin</artifactId>
    	<version>${mule.maven.plugin.version}</version>
    	<extensions>true</extensions>
    	<configuration>
    	<sharedLibraries>
        <!-- MySQL driver dependency configured as a shared library -->
        <sharedLibrary>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
        </sharedLibrary>
      </sharedLibraries>
      </configuration>
    </plugin>
  </plugins>
</build>

</dependencies>
  <!--Database Connector dependency -->
  <dependency>
    <groupId>org.mule.connectors</groupId>
    <artifactId>mule-db-connector</artifactId>
    <version>1.5.0</version>
    <classifier>mule-plugin</classifier>
  </dependency>
  <!-- MySQL driver dependency -->
  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.33</version>
  </dependency>
</dependencies>

Configure Additional Plugin Dependencies

You can configure additional plugin dependencies for the connectors in your application.
To configure additional plugin dependencies, add the following elements in your Mule Maven plugin configuration inside your project’s pom.xml file:

<additionalPluginDependencies>
    <plugin>
        <groupId>${connectorGroupID}</groupId>
        <artifactId>${connectorArtifactID}</artifactId>
        <additionalDependencies>
            <dependency>
                <groupId>${dependencyGroupID}</groupId>
                <artifactId>${dependencyArtifactID}</artifactId>
                <version>${dependencyVersion}</version>
            </dependency>
        </additionalDependencies>
    </plugin>
</additionalPluginDependencies>

The following example configures the Derby driver as a dependency of Database Connector:

<plugin>
    <!-- Mule Maven Plugin configuration -->
    <groupId>org.mule.tools.maven</groupId>
    <artifactId>mule-maven-plugin</artifactId>
    <version>${mule.maven.plugin.version}</version>
    <configuration>
        <!-- Plugin dependencies configuration-->
        <additionalPluginDependencies>
            <!-- The connector for which the dependency is defined -->
            <plugin>
                <groupId>org.mule.connectors</groupId>
                <artifactId>mule-db-connector</artifactId>
                <!-- Dependencies definition for the connector -->
                <additionalDependencies>
                    <dependency>
                        <groupId>org.apache.derby</groupId>
                        <artifactId>derby</artifactId>
                        <version>10.11.1.1</version>
                    </dependency>
                </additionalDependencies>
            </plugin>
        </additionalPluginDependencies>
    </configuration>
</plugin>