Edit

Share via


Connect to an Azure Artifacts feed - Maven

Azure DevOps Services | Azure DevOps Server 2022 | Azure DevOps Server 2020

Azure Artifacts enables developers to publish and restore Maven packages from feeds and public registries such as Maven Central and Google Maven Repository. This article walks you through setting up your Maven project and connecting to an Azure Artifacts feed.

Prerequisites

Product Requirements
Azure DevOps - An Azure DevOps organization.
- An Azure DevOps project.
- An Azure Artifacts feed.
- Download and Install Apache Maven.

Project setup

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts, select your feed from the dropdown menu, and then select Connect to feed.

  3. In the left navigation pane, select Maven. Make sure you've installed the prerequisites, if not, select Get the tools in the top-right corner to download and install them.

  4. In the Project setup section, copy the repository snippet and add it to your pom.xml file within the <repositories> and distributionManagement> sections. Your file should resemble the following:

    <repositories>
      <repository>
        <id>FEED_NAME</id>
        <url>https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1</url>
        <releases>
          <enabled>true</enabled>
        </releases>
        <snapshots>
          <enabled>true</enabled>
        </snapshots>
      </repository>
    </repositories>
    <distributionManagement>
      <repository>
        <id>FEED_NAME</id>
        <url>https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1</url>
        <releases>
          <enabled>true</enabled>
        </releases>
        <snapshots>
          <enabled>true</enabled>
        </snapshots>
      </repository>
    </distributionManagement>
    
  5. Add the provided snippet to your local settings.xml (located in ${user.home}/.m2):

      <servers>
        <server>
          <id>FEED_NAME</id>
          <username><ORGANIZATION_NAME></username>
          <password>[PERSONAL_ACCESS_TOKEN]</password>
        </server>
      </servers>
    
  6. Generate a Personal Access Token with Packaging > Read & write scopes, and paste it into the <password> tag in your settings.xml file.

  1. Sign in to your Azure DevOps collection, and then navigate to your project.

  2. Select Artifacts, select your feed from the dropdown menu, and then select Connect to feed.

  3. In the left navigation pane, select Maven. Make sure you've installed the prerequisites, if not, select Get the tools in the top-right corner to download and install them.

  4. In the Project setup section, copy the repository snippet and add it to your pom.xml file within the <repositories> and distributionManagement> sections. Your file should resemble the following:

      <repositories>
        <repository>
          <id>FEED_NAME</id>
          <url>http://<SERVER_NAME>/<COLLECTION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <distributionManagement>
        <repository>
          <id>FEED_NAME</id>
          <url>http://<SERVER_NAME>/<COLLECTION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </distributionManagement>
    
  5. Add the provided snippet to your local settings.xml (located in ${user.home}/.m2):

      <servers>
        <server>
          <id>FEED_NAME</id>
          <username><COLLECTION_NAME></username>
          <password>[PERSONAL_ACCESS_TOKEN]</password>
        </server>
      </servers>
    
  6. Generate a Personal Access Token with Packaging > Read & write scopes, and paste it into the <password> tag in your settings.xml file.

Tip

If your settings.xml file is shared across your team, you can use Maven to encrypt your passwords.