This topic provides details on configuring Maven to work with Artifactory.
Pre-requisite: Before connecting your Maven client to Artifactory, you must have an existing Maven repository in Artifactory. For more information, see Create a Maven Repository
Configure your Maven Client
To configure Maven to resolve artifacts through Artifactory, you need to modify the settings.xml file. You can generate one automatically or create and modify it manually. The instructions provided here explain how to create and modify settings.xml. manually.
The definitions in the generated settings.xml file override the default central and snapshot repositories of Maven.
If you want to use an identity token instead of your Artifactory password for configuring your Maven client with Artifactory, follow the instructions here.
Note
JFrog recommends using an identity token for configuring your Maven client, as it has certain advantages over a user password. However, it is not strictly required.
Create and modify the settings.xml file according to the following steps:
Copy the contents of the settings.xml file below to an XML editor:
<?xml version="1.0" encoding="UTF-8"?> <settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <servers> <server> <username>${ARTIFACTORY_USER}</username> <password>${ARTIFACTORY_TOKEN}</password> <id>central</id> </server> <server> <username>${ARTIFACTORY_USER}</username> <password>${ARTIFACTORY_TOKEN}</password> <id>snapshots</id> </server> </servers> <profiles> <profile> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name><release_repo></name> <url>https://<my_jfrog_domain>/artifactory/<release_repo></url> </repository> <repository> <snapshots /> <id>snapshots</id> <name><snapshot_repo></name> <url>https://<my_jfrog_domain>/artifactory/><snapshot_repo}</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name><plugin_release_repo></name> <url>https://<my_jfrog_domain>/artifactory/<plugin_release_repo></url> </pluginRepository> <pluginRepository> <snapshots/> <id>snapshots</id> <name><plugin_snapshot_repo></name> <url>https://<my_jfrog_domain>/artifactory/<plugin_snapshot_repo></url> </pluginRepository> </pluginRepositories> <id>artifactory</id> </profile> </profiles> <activeProfiles> <activeProfile>artifactory</activeProfile> </activeProfiles> </settings>In the settings.xml, replace the following placeholders as follows:
${ARTIFACTORY_USER}: Replace with your Artifactory username.
${ARTIFACTORY_TOKEN}: Replace with your identity token or Artifactory password.
<my_jfrog_domain>: Replace with the name of your Artifactory domain.
<release_repo>: Replace with the repository from which to resolve releases.
<snapshot_repo>: Replace with the repository from which to resolve snapshots.
<plugin_release_repo>: Replace with the repository from which to resolve plugin releases.
<plugin_snapshot_repo>: Replace with the repository from which to resolve plugin snapshots.
Save the settings.xml file in one of the following locations, according to your system needs:
User-specific install: ${user.home}/.m2/settings.xml
Global machine install: ${maven.home}/conf/settings.xml
Custom settings.xml file: Pass it as an argument during execution, for example: mvn install -s settings.xml
Note
You can also use JFrog Set me up to copy the snippet populated with your token and environment. For more information, see Use Artifactory Set Me Up for Configuring Package Manager Clients.
Next Step: