In the first blog of this series, we created a deployment approach using Maven settings.xml and pom.xml that we use for each Mule project. This lets you use standard Maven commands to build Mule projects, publish them to an artifact repository, and deploy them to Anypoint Runtime Manager.
This blog provides a cheat sheet with a list of many Maven commands that can be used with the standard settings.xml and pom.xml files. All commands are meant to be run from a command-line shell (such as bash or gitBash).
Documentation syntax
The commands have optional parameters enclosed in square brackets. For example, the following command shows the -DskipTests as an optional parameter, meaning that -DskipTests is not required. Optional parameters affect the operation of a command, in this case, the Munit tests are not run if -DskipTests is specified:
mvn clean install [-DskipTests]
Parameter values enclosed in curly brackets are required values. For instance the following command requires a value for an Anypoint user name (-Du parameter) and password (-Dp parameter):
mvn clean install -DskipTests -Du={ap_user_name} -Dp={ap_password}
In commands that deploy the Mule project to the ARM, the parameter -Denv={xxx} is used to note that the {xxx} should be replaced with the deployment environment profile name. These will be your customized environment names (dev, test and prd in the original blog sample files).
If there are no curly or square brackets, the command options should be used as shown.
Anypoint username and password
If you are using a bash shell (or GitBash for Windows), you can store the u and p parameters as exported (system) variables and let the mvn command pull the values from the system variables instead of typing them on the command line. This conceals the username and password if you are showing others various mvn commands and do not want to share the values.
Similarly, use the build server’s credential vault facility to substitute the username and password in the pipeline script. For example:
mvn clean install -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
Where the values ANYPOINT_USR and ANYPOINT_PWD are replaced by the build server stored values.
Maven command cheat sheet
These are the Maven commands that can be used.
- Build and deploy to local workstation repository:
mvn clean install [-DskipTests] [-Du=${ANYPOINT_USR}] [-Dp=${ANYPOINT_PWD}]
- Build and publish to corporate artifact repository:
mvn clean deploy -Partifact-repo [-DskipTests] [-Du=${ANYPOINT_USR}] [-Dp=${ANYPOINT_PWD}]
- Build and publish to Exchange:
mvn clean deploy -Pexchange [-DskipTests] -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
- Build and deploy to CloudHub behind public shared load balancer:
mvn clean install mule:deploy -Pcloudhub -Denv={xxx} -Ppublic-lb [-DskipTests] -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
- Build and deploy to CloudHub behind DLB:
mvn clean install mule:deploy -Pcloudhub -Denv={xxx} -Pdlb -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
- Build and deploy to Mule Standlone:
mvn clean install mule:deploy -Phybrid -Denv={xxx} -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
- Deploy Bbnary to CloudHub behind public shared load balancer:
mvn mule:deploy -Dmule.artifact={xx.jar} -Pcloudhub -Denv={xxx} -Ppublic-lb -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
- Deploy binary to CloudHub behind DLB:
mvn mule:deploy -Dmule.artifact={xx.jar} -Pcloudhub -Denv={xxx} -Pdlb -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
- Deploy binary to Mule standalone:
mvn mule:deploy -Dmule.artifact={xx.jar} -Phybrid -Denv={xxx} -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
- Deploy binary to Runtime Fabric:
mvn mule:deploy -Dmule.artifact=dummy.jar -Prtf -Denv={xxx} -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
- Copy the binary artifact jar from Exchange:
mvn dependency:copy -Dartifact=${groupId}:${artifactId}:${version}:jar:mule-application -DoutputDirectory=./ -B -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
The groupId, artifactId, and version are the values in the Mule project’s pom.xml.
- Copy the artifact pom.xml from Exchange:
mvn dependency:copy -Dartifact=${groupId}:${artifactId}:${version}:pom -DoutputDirectory=./ -B -Du=${ANYPOINT_USR} -Dp=${ANYPOINT_PWD}
The groupId, artifactId, and version are the values in the Mule project’s pom.xml. The copied pom file will need to be renamed from ${artifactId}-${artifactVersion}.pom to pom.xml
The next blog in this series will illustrate the use of these standard Maven commands in a standardized build server script. Learn more about Anypoint Platform deployment models.