Contact Us 1-800-596-4880

Maven Reference

Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule reached its End of Life on November 2, 2022, 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.

This page summarizes reference information that helps you work when using Maven with Mule. Refer to Maven Support in Mule for an introduction and overview.

pom.xml File

<project root>/pom.xml

Project Object Model file that defines settings for a Maven project describing an application. It includes all settings necessary to build the application such as build plugin configurations. Note that the pom.xml exists on a per-project basis and is distributed along with a project.

settings.xml File

<system-wide Maven directory>/settings.xml
<user home directory>/.m2/settings.xml

Contains global settings for your Maven installation. Unlike a project’s pom.xml, it defines system-wide settings and is not distributed with a project, since it can contain confidential information such as authentication credentials.

The settings.xml file can reside in two locations:

  • In a system-wide settings folder:

    In this case, it is a global settings.xml file that defines the settings for all Maven installations on the system, regardless of user. For example:

    /etc/maven2/settings.xml
  • In a user-specific settings folder:

    In this case, it is a user settings.xml file that is relevant only for a specific user’s Maven installation. The default location is the .m2 directory in the user’s home directory:

    /home/joe/.m2/settings.xml

On a system with both global and user settings.xml files, the settings from both files become merged. In case there are duplicate settings, the user’s settings take precedence over the global settings.

Mule Repositories

When you create a new Mule project in Anypoint Studio, the required Mule repositories are automatically added to the pom.xml file. If you are creating the Mule project outside Studio, add the following repositories to the pom.xml file:

<repositories>
    <repository>
        <id>anypoint-exchange</id>
        <name>Anypoint Exchange</name>
        <url>https://maven.anypoint.mulesoft.com/api/v1/maven</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>mulesoft-releases</id>
        <name>MuleSoft Releases Repository</name>
        <url>https://repository.mulesoft.org/releases/</url>
        <layout>default</layout>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>mulesoft-releases</id>
        <name>MuleSoft Releases Repository</name>
        <layout>default</layout>
        <url>https://repository.mulesoft.org/releases/</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

Useful Commands

The following set of commands enables you to retrieve information about your Maven installation and to perform project-related tasks.

Locate the Maven binary and other files (Unix)

whereis mvn

Locate Maven files such as global configuration files (Unix)

locate maven

Obtain Maven version

mvn --version

This also provides other information such as the Java home directory, locale and processor architecture.

Obtain a List of Maven Commands and Options

mvn -h

Check the Manual Page for Maven (Unix)

man mvn

Create a Project

mvn archetype:generate -DgroupId=com.company.app -DartifactId=myapp -DarchetypeArtifactId=myarchetypeid -DinteractiveMode=false

Build a Project

mvn package

Clean a Project

mvn clean

Generate a Site

mvn site

Obtain a List of JAR Files Included in Your Artifact

mvn dependency:build-classpath

Obtain the Dependency Tree for Your Artifact

mvn dependency:tree

Deploying Mule Artifacts to a Central Maven Repository

Using a central repository can save users' time when building applications. To deploy to a central repository, you need to deploy the Mule POM files and JAR artifacts to the desired repository.

The deploy plugin is primarily used during the deploy phase, to add your artifacts to a remote repository for sharing with other developers and projects.

Deploying pom.xml

To deploy the pom.xml to a remote repository, use the following command:

mvn deploy:deploy-file
-DgroupId=${project.groupId}
-DartifactId=${project.artifactId}
-Dversion=${version}
-Dpackaging=pom
-Dfile=${localPom.canonicalPath}
-Durl=http://<your_repository_ip>/nexus/content/repositories/releases
-DrepositoryId=releases

For the -Durl parameter, replace <your_repository_ip> with the correct IP address. Also, the -DrepositoryId needs to match with the credentials defined in the settings.xml file.

Deploying the JAR files

To deploy a JAR file to a remote repository, use the following command:

mvn deploy:deploy-file
-DgroupId=${pomProps.groupId}
-DartifactId=${pomProps.artifactId}
-Dversion=${pomProps.version}
-Dpackaging=jar
-Dfile=${f.canonicalPath}
-DpomFile=${localPom.canonicalPath}
-Durl=http://${your_repository_ip}/nexus/content/repositories/releases
-DrepositoryId=releases

For the -Durl parameter, replace your_repository_ip with the correct IP address. Also, the -DrepositoryId needs to match with the credentials defined in the settings.xml file.

If you wish to both install the JAR files locally and deploy them remotely, you can keep both locations in the argument definition.