Configuring Maven POM Files and Settings
This page includes instructions for configuring your Maven installation to work successfully with Mule. It covers how to maintain your POM file to add or adjust dependencies and point to the correct MuleSoft repositories, and how to access and adjust your settings.xml file with credentials and profiles for the Enterprise repo.
This document assumes that you are working with Maven outside of Anypoint™ Studio, and thus will be using archetypes to build Mule applications. See Using Maven with Mule for an overview of using Maven to manage your Mule projects.
|Note that you generally do not need to modify your settings.xml file if you are working with Maven through Studio, as Studio keeps track of the dependencies you’ll need and attempts to manage them for you in the application’s associated POM file. If dependency errors occur, you may need to manually adjust your POM file, and, in some cases, in your settings.xml. Refer to the Maven documentation for the pom.xml and settings.xml for specific instructions.|
Before you can start using Maven to create new Mule projects from the command line using archetypes, you need to:
Ensure that Maven is installed in a directory that does not include spaces.
Create or maintain your already-created
pom.xmlfiles for your applications to include references to the MuleSoft open-source repositories and any connectors, modules, or other extensions that you need to include in each application.
Enterprise users only: Modify the
settings.xmlfile to point to the Enterprise Customer repository and provide your credentials.
By default, your local Maven installation stores configuration files in the directory
~/.m2 on Unix and Mac;
C:\Documents and Settings\<user>\.m2 on Windows). Keep in mind that in Linux or Mac
.m2 is a hidden folder.
If you are building your project outside Studio, you need to manually add some required JARs which cannot be accessed publicly through Maven. However, the command line tool
populate_m2_repo, which is available in your
$MULE_HOME/bin directory, can fetch all the associated files. Note: Avoid duplicating jars in your project which causes classloading errors.
Execute one of the following commands:
my-m2-test-repository must not already exist in the current directory.)
Note that you may encounter errors if your
MULE_HOME is set to a path containing spaces. It is recommended that you select a
MULE_HOME location that does not contain spaces.
Each Maven project has a POM (Project Object Model) file that consists of an XML representation of your project. Read more about POM files in the Maven documentation.
When you create a Maven project, either using Studio or via the command line using a Maven archetype, you are generating a POM file. Navigate to that POM file and open it to inspect its contents or make manual adjustments, if necessary.
If they are not already present, add references to the open-source MuleSoft repositories.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <repositories> ... <repository> <id>mulesoft-releases</id> <name>MuleSoft Repository</name> <url>https://repository-master.mulesoft.org/releases/</url> <layout>default</layout> </repository> <repository> <id>mulesoft-snapshots</id> <name>MuleSoft Snapshot Repository</name> <url>https://repository-master.mulesoft.org/snapshots/</url> <layout>default</layout> </repository> ... </repositories>
If the dependencies that you need are not already present, add them as shown.
1 2 3 4 5 6 7 8 9 <dependencies> ... <dependency> <groupId>GROUP ID OF DEPENDENCY</groupId> <artifactId>ARTIFACT ID OF DEPENDENCY</artifactId> <version>VERSION OF DEPENDENCY</version> </dependency> ... <dependencies>
For example, if you were adding the dependency for the Salesforce connector:
1 2 3 4 5 6 7 8 9 <dependencies> ... <dependency> <groupId>org.mule.modules</groupId> <artifactId>mule-module-sfdc</artifactId> <version>LATEST</version> </dependency> ... <dependencies>
Not sure what the dependency details are for a connector that you need? Refer to the connector-specific Maven instructions on the connectors site.
This section assumes that you have acquired an http://www.mulesoft.com/mule-esb-support-esb-license-subscription[Enterprise License] and credentials for the https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/[MuleSoft Enterprise Maven customer repository], which allows you to access Mule Enterprise modules, connectors, and other components not included in the trial or community versions. If you are a MuleSoft customer and do not have access to the repository, contact https://www.mulesoft.com/support-and-services/mule-esb-support-license-subscription[MuleSoft Support].
To configure Maven to access the MuleSoft Customer Repository, you need to make additions to the
settings.xml config file. Your
.m2 directory may already contain a configuration file called
settings.xml. Note that this file is not mandatory; Maven uses default parameters if the file is not present. If you don’t have a
settings.xml file at all, create it inside the
~/.m2 folder. Read more about the
settings.xml file in the http://maven.apache.org/settings.html[Maven documentation].
Open the file <`USER_HOME>/.m2/settings.xml` for editing.
Add the following to the
1 2 3 4 5 6 7
<server> <id>MuleRepository</id> <username>YOUR_ID</username> <password>YOUR_PASSWORD</password> </server>
Add the following to the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<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>