Contact Us 1-800-596-4880

Maven Reference

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.

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.

MuleSoft Repositories

When you create a new Mule project in Anypoint Studio, the required MuleSoft repositories are automatically added to the project. If you create the Mule project outside Studio, you have to manually add the repositories to the pom.xml file and also configure your credentials for Maven to access the enterprise repository.

Configure MuleSoft Public Repositories

To configure the public MuleSoft repositories, add the following to your project’s 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>

Configure MuleSoft Enterprise Repository

To add access to the enterprise repository to your project, you must obtain and install an Enterprise license, acquire access to the repository, and configure the repository in your project.

Obtain and Install an Enterprise License

See Installing an Enterprise License, for instructions to acquire or install an Enterprise license

Acquire Access to Enterprise Repositories

If you are a MuleSoft customer and do not have credentials to access the MuleSoft Enterprise repository, contact Support and request Nexus enterprise credentials.

Configure Maven to Access MuleSoft Enterprise Repository

To configure Maven to access the enterprise repository:

  1. Navigate to <USER_HOME>/.m2/settings.xml.

  2. Open settings.xml on all workstations that require access. If the settings.xml file does not exist, create it.

    Read more about the settings.xml file in the Maven documentation.

  3. Add the following syntax to the servers section in each settings.xml file:

    <servers>
    ...
        <server>
    
            <id>MuleRepository</id>
            <username>YOUR_ID</username>
            <password>YOUR_PASSWORD</password>
    
        </server>
    ...
    </servers>
  4. Add the following syntax to the profile section in each settings.xml file:

    <profiles>
    ...
        <profile>
    
            <id>Mule</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <repositories>
                <repository>
                    <id>MuleRepository</id>
                    <name>MuleRepository</name>
                    <url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
                    <layout>default</layout>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
    
        </profile>
    ...
    </profiles>

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.