Get started with Maven feeds and Artifacts

Azure DevOps Services | TFS 2018

Before you start

This quickstart assumes you've already set up Azure Artifacts. You can check out how to license the extension in the License Azure Artifacts guide.

Note

Azure Artifacts is an extension that comes pre-installed on TFS 2017 or newer (Maven is only available in 2018 or newer), if it was removed from your organization, you can install it from the Marketplace page for Azure Artifacts.

Prerequisites

  1. Apache Maven installed. You can download it from the Apache Maven site.

  2. Have Azure Artifacts installed in your organization.

Create a feed

Already have a feed? Skip to the next step.

There are two types of feeds: project scoped and organization scoped feeds. All public feeds are project-scoped and they inherit the visibility settings of the hosting project.

  1. Go to Azure Artifacts.

    Go to Azure Artifacts

  2. Select Create Feed.

    New feed button

  3. Give your feed a Name and choose its visibility, upstream sources and scope.

    New feed dialog box

  4. Select Create.

Note

Enabling upstream sources allow you to use your favorite OSS packages and gives you more protection against outages and corrupted or compromised packages.

Azure Artifacts is installed by default for TFS 2017 customers. You must upgrade to TFS 2017 in order to use Azure Artifacts. If this is the first time using your feed, you might be asked to assign a license

  1. Go to Build & Release and select Packages.

    Go to Azure Artifacts TFS

  2. Select + New feed.

    New feed button TFS

  3. Give your feed a Name, a Description, and set up who can read, who can contribute and if you want to Include external packages.

    New feed dialog box TFS

Note

Enabling upstream sources allow you to use your favorite OSS packages and gives you more protection against outages and corrupted or compromised packages.

See Feeds and views permissions to learn more about managing feed permissions.

Set up authentication

To talk to Azure Artifact feeds, you'll need a token on your local machine that Maven can pick up and pass to Azure DevOps Services.

  1. From the Azure Artifacts page, select Connect to Feed.

    Connect to feed button on the upper right of the page

  1. From the Packages page, select Connect to Feed.

    Connect to feed button on the upper right of the page

  1. Open the Maven tab under the maven header.

    • Maven pulls credentials from your settings.xml file.

    • On Linux, the file path is usually "${user.home}/.m2/settings.xml".

    • On macOS, the file path is usually "~/.m2/settings.xml".

    • On Windows, the file path is usually "%USERPROFILE%/.m2/settings.xml".

    • If the file doesn't exist, create one now.

    Tip

    To make sure you create and save your new XML file in the correct format, set File Explorer to show file name extensions:

    1. In File Explorer, select the View tab.
    2. Under Show/hide, select the File name extensions check box to see your files extensions in File Explorer.
  2. If you haven't installed Maven on your machine, you can select Get the tools to download and install it.

  3. Follow the Project setup section including generating a personal access token.

    Set up Maven authentication

You can find more information about the settings.xml file in the settings.xml reference.

Publish an artifact

Publish Maven artifacts to a feed in Azure Artifacts to share them with your team and organization.

To publish a Maven artifact, you'll need to have a Maven artifact to publish on your local machine. If you don't have one, you can generate one by running the following command:

mvn -B archetype:generate -DarchetypeGroupId="org.apache.maven.archetypes" -DgroupId="MyGroup" -DartifactId="myFirstApp"
  1. Set up the Maven client with your feed.

  2. Navigate to the directory containing your Maven artifact's pom.xml file. If you've just created an artifact, the pom.xml file will be in the myFirstApp folder.

  3. From the directory containing your pom.xml file, run the following commands to build and deploy your Maven artifact:

    • Build your package:

      mvn build
      
    • Publish your package:

      mvn deploy
      

Your Maven artifact should appear in your feed now. See the Apache Maven Deploy Plugin to learn more about Maven deployment.

Tip

If you want to publish a 3rd party assembly to a Maven feed, you can use the deploy:deploy-file Mojo. This mojo is used primarily to publish artifacts that were not built by Maven and you can use it with or without a POM file.

mvn deploy:deploy-file -Dpackaging="jar" -DrepositoryId="MyFeedName" -Durl="MyFeedURL" -DgroupId="MyGroup" -DartifactId="myFirstApp" -Dversion="jarFileVersion" -Dfile="jarFileLocalPath"

Important

Maven snapshot artifacts are not currently supported in upstream sources.

Install an artifact from your feed

Install Maven artifacts from your feed by using the Maven client.

The most common way to install a Maven artifact is as a dependency of another artifact.

  1. Create a Maven artifact by using the following command:

    mvn -B archetype:generate -DarchetypeGroupId="org.apache.maven.archetypes" -DgroupId="MyGroup" -DartifactId="mySecondApp"
    
  2. In Azure Artifacts, browse to the artifact that you want to install and copy the contents of the <dependency> element.

  3. Paste the <dependency> element content inside the <dependencies> element of your pom.xml file.

  4. Run mvn install from the directory that contains your pom.xml file.

See the Maven CLI docs for more installation options.

  1. Create a Maven artifact by using the following command:

    mvn -B archetype:generate -DarchetypeGroupId="org.apache.maven.archetypes" -DgroupId="MyGroup" -DartifactId="mySecondApp"
    
  2. From the Connect to feed dialog box in TFS, copy the <repository> information. Paste it into your pom.xml file twice (see the preceding sample file):

    • Between the <repositories> tags
    • Between the <distributionManagement> tags
  3. From the Packages page, browse to the artifact that you want to install and copy the contents of the <dependency> element.

  4. Paste the <dependency> element content inside the <dependencies> element of your pom.xml file.

  5. Run mvn install from the directory that contains your pom.xml file.

See the Maven CLI docs for more installation options.

Automate the process with continuous integration

You can use continuous integration systems such as Team Build to automate the installation and publishing of your Maven artifacts. To get started with continuous integration, see the Maven in Team Build guidance.

What's next?

Check out the Azure Artifacts landing page to learn about other topics.