Edit

Share via


Use packages from Maven Central

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

Using Azure Artifacts upstream sources allows you to use a single feed to host both your own packages and packages from public registries such as Maven Central. When upstream sources are enabled, Azure Artifacts automatically saves a copy of any package installed from an upstream source. This ensures your development process can continue seamlessly even if a public registry experiences an outage.

Note

Maven snapshots are not supported in Maven upstream sources.

Prerequisites

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

Create a feed

If you already have an Azure Artifacts feed, skip to the next section. Otherwise, follow these steps to create one:

  1. Sign in to Azure DevOps and navigate to your project.

  2. Select Artifacts, then select Create Feed.

  3. Provide a Name for your feed, set the Visibility to control who can access your packages, and choose the feed Scope. Make sure to check Include packages from common public sources to enable upstream sources and allow consumption of packages from public registries.

  4. Select Create to finish creating the feed.

Add Maven Central upstream

If you selected the upstream sources checkbox when setting up your feed, Maven Central should already be added as an upstream source. Otherwise, you can manually add it by following these steps:

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

  2. Select Artifacts, then select the gear icon button in the top right corner to navigate to your Feed Settings.

  3. Select Upstream sources, then select Add Upstream.

  4. Select Public source, select Maven Central (https://repo.maven.apache.org/maven2/) from the dropdown menu, and then select Add when you're done.

  5. Select Save in the top right corner to save your changes.

    A screenshot showing how to save upstream sources.

Connect to your feed

Before you can start saving packages from upstream sources, you must first set up your project and connect to your feed.

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

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

  3. Select Connect to Feed, then select Maven from the left panel.

  4. Make sure you've installed the prerequisites, then follow the steps in the Project setup section to set up your pom.xml and settings.xml files and connect to your feed. See Project setup - Maven for more details.

Use packages from Maven Central

The following example illustrates how to consume the Apache HttpClient package from Maven Central using the command line.

Note

To save packages from upstreams, you must have the Feed and Upstream Reader (Collaborator) role or higher. See Feed roles and permissions for more details.

  1. Navigate to Maven Central https://mvnrepository.com/.

  2. Search for Apache HttpClient. Select the package, then select the version you wish to install.

  3. Under the Maven tab, copy the <dependency> snippet:

    <dependency>
      <groupId>org.apache.httpcomponents.client5</groupId>
      <artifactId>httpclient5</artifactId>
      <version>5.5.1</version>
    </dependency>
    
  4. Open your pom.xml file and paste the snippet inside the <dependencies> tag, then save your file.

  5. Run the following command from the same directory as your pom.xml file to install your dependencies:

    mvn install
    

View saved packages

Now that you've installed a package from Maven Central, you can see how Azure Artifacts automatically saved a copy of that package to your feed. You can filter your feed view to see packages saved from different upstream sources.

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

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

  3. From the source dropdown, select Maven Central to filter for packages from this upstream.

  4. The Apache HttpClient* package that you saved in the previous step is now available in your feed.

    A screenshot displaying the Apache HttpClient package that was saved from Maven Central.

Tip

If Maven is not downloading all your dependencies, run the following command from the project directory to regenerate your project files: mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true