Skip to content

Latest commit

 

History

History
215 lines (166 loc) · 7.67 KB

install.md

File metadata and controls

215 lines (166 loc) · 7.67 KB
title description ms.service ms.assetid ms.manager ms.topic ms.custom ms.date monikerRange recommendations
Restore Maven packages from your Azure Artifacts feed
Learn how to connect to your Azure Artifacts feed and restore your Maven packages.
azure-devops-artifacts
0f66e727-e76a-4a72-be12-3fa1775b9e2c
mijacobs
conceptual
engagement-fy23
06/11/2024
<= azure-devops
true

Restore Maven packages from your Azure Artifacts feed

[!INCLUDE version-lt-eq-azure-devops]

With Azure Artifacts, you can publish and restore Maven packages from Azure Artifacts feed and public registries. This article will walk you through setting up your Maven project, connecting to your Azure Artifacts feed, and restoring your Maven packages.

Prerequisites

Connect to a feed

::: moniker range="azure-devops"

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

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

  3. Select Connect to feed, and then select Maven from the left navigation area.

  4. If this is your first time using Azure Artifacts with Maven, make sure you've installed the prerequisites. Otherwise select Get the tools in the top-right corner to install them.

  5. Follow the instructions in the Project setup section to set up your pom.xml and settings.xml files. Your files should resemble the following examples:

    • pom.xml:

        <repositories>
          <repository>
            <id>MavenDemo</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>MavenDemo</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>
    • settings.xml:

        <servers>
          <server>
            <id>MavenDemo</id>
            <username><ORGANIZATION_NAME></username>
            <password>[PERSONAL_ACCESS_TOKEN]</password>
          </server>
        </servers>
  6. Generate a Personal Access Token with Packaging > Read & write scope, and then paste it into the <password> tag.

::: moniker-end

::: moniker range="azure-devops-2020 || azure-devops-2022"

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

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

  3. Select Connect to Feed, and then select Maven from the left navigation pane.

  4. If this is your first time using Azure Artifacts with Maven, make sure you've installed the prerequisites, otherwise select Get the tools in the top-right corner to install them.

  5. Follow the instructions in the Project setup section to set up your pom.xml and settings.xml files. Your files should resemble the following examples:

    • pom.xml:

        <repositories>
          <repository>
            <id>MavenDemo</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>MavenDemo</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>
    • settings.xml:

        <servers>
          <server>
            <id>MavenDemo</id>
            <username><COLLECTION_NAME></username>
            <password>[PERSONAL_ACCESS_TOKEN]</password>
          </server>
        </servers>
  6. Generate a Personal Access Token with Packaging > Read & write scope, and then paste it into the <password> tag.

::: moniker-end

::: moniker range="azure-devops-2019"

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

  2. Select Artifacts, and then select your feed.

  3. Select Connect to Feed, and then select Maven from the left navigation pane.

  4. Select Generate Maven Credentials and add the credentials to your user settings.xml file inside the <servers> tag. Your file should look like the following example:

      <servers>
        <server>
          <id>server-2019-defaultcollection-demo</id>
          <username><FEED_NAME></username>
          <password>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</password>
        </server>
      </servers>
  5. Add the second snippet to your project's pom.xml inside both the <repositories> and <distributionManagement> tags. Your file should look like the following example:

      <repositories>
        <repository>
          <id>server-2019-defaultcollection-demo</id>
          <url>http://<SERVER_NAME>/<COLLECTION_NAME>/_packaging/<FEED_NAME>/maven/v1</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <distributionManagement>
        <repository>
          <id>server-2019-defaultcollection-demo</id>
          <url>http://<SERVER_NAME>/<COLLECTION_NAME>/_packaging/<FEED_NAME>/maven/v1</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </distributionManagement>

::: moniker-end

Tip

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

Restore packages

Run the following command in your project directory to restore your packages:

mvn install

Note

Ensure that the <id> tags in your settings.xml and pom.xml files match exactly.

Related articles