{{announcement.body}}
{{announcement.title}}

Mule Maven Plugin for CloudHub Deployment

DZone 's Guide to

Mule Maven Plugin for CloudHub Deployment

Explore the Mule Maven plugin for CloudHub deployment.

· Integration Zone ·
Free Resource

The deployment of Mule applications can be managed using Maven. The Mule Maven plugin allows integrating the packaging, testing, and deployment of Mule applications with the Maven lifecycle.

It helps in automating the application deployment.

Add the plugin in POM.xml if not added already.

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

In the plugin, add the configuration tag to define parameters for CloudHub deployment.

<configuration>
<cloudHubDeployment>
      <uri>https://anypoint.mulesoft.com/</uri>
      <muleVersion>mule-version</muleVersion>
      <username>platform-username</username>
      <password>platform-password</password>
      <applicationName>cloudhub-application-name</applicationName>
      <environment>anypoint-environment</environment>
      <properties>
        <key>value</key>
      </properties>
  </cloudHubDeployment>
</configuration>

The properties tag can be used to define application properties if required.  

Other tags are self-explanatory, like Anypoint username, password, applicationName, etc.

The plugin gives the option to configure the region (default value is us-east-1), business group, environment to deploy to, number of workers (1 by default), vCores (0.1 by default) required, and artifact to deploy (can be mentioned by giving the absolute file location).

<region>eu-west-1</region>
<workers>1</workers>
<workerType>SMALL </workerType>
<artifact>path/to/file</artifact>

If the artifact tag is not defined, the JAR/ ZIP generated during the package phase will be used for deployment.

Accepted values for region: 

  1. us-east-1 - US East (N. Virginia)
  2. us-west-2 - US West (Oregon)
  3. eu-west-1 - EU (Ireland)
  4. ap-southeast-2 - Asia Pacific (Sydney)
  5. ap-southeast-1 - Asia Pacific (Singapore)
  6. us-west-1 - US West (N. California)
  7. eu-central-1 - EU (Frankfurt)
  8. ap-northeast-1 - Asia Pacific (Tokyo)
  9. eu-west-2 - EU (London)
  10. ca-central-1 - Canada (Central)
  11. sa-east-1 - South America (São Paulo)
  12. us-east-2 - US East (Ohio)

Accepted values for workerType: MICRO(0.1 vCores), SMALL (0.2 vCores), MEDIUM (1 vCores), LARGE (2 vCores), XLARGE (4 vCores), XXLARGE (8 vCores), 4XLARGE (16 vCores)

To deploy the application, run the maven deploy phase and one argument -DmuleDeploy

mvn clean deploy -DmuleDeploy

Without -DmuleDeploy argument, the system will throw the following exception: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

The plugin configuration can be edited to skip passing -DmuleDeploy in command.

<executions>
  <execution>
    <id>deploy</id>
    <phase>deploy</phase>
    <goals>
      <goal>deploy</goal>
    </goals>
  </execution>
</executions>

Add the executions tag under the configuration of the plugin. Now running mvn clean deploy will deploy the application to CloudHub.

In the plugin configuration, instead of giving the Anypoint username and password, we have the option to pass server id, which will be defined under servers in the settings file of Maven. This is :

<server>
  <username>anypoint-username</username>
  <password>anypoint-password</password>
  <id>server-id</id>
</server>

Change the plugin configuration, add the server tag, and remove the username and password.

<cloudHubDeployment>
  ...
  <server>server-id</server>
  ...
</cloudHubDeployment>

Thanks for reading!

Topics:
mule maven plugin ,cloudhub ,mule ,integration

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}