Get started with Maven Package Management in Team Services and TFS

Last Update: 5/16/2017

Before you start

This guide assumes you've already set up Package Management. You can check out how to install and license the extension in the Install and license Package Management guide, or go directly to the Extensions Marketplace listing to install.

Prerequisites

  1. Apache Maven installed. It can be downloaded from the Apache Maven Site.
  2. Have Package Management installed in your Team Services account.
  3. [Public-opt in only] - To enable Maven support for your account, ask your account admin to go to the "Preview Features" section, choose "for this account", and enable "Maven for Package Management". (Preview Features docs)

Create a feed

Already have a feed? Skip to the next step.

A feed is a container for packages. You consume and publish packages through a particular feed.

To get started, navigate to the Package hub in the Build & Release hub group:

Go to Package hub

If you don't see the Package hub, then ask your account owner to install the Package Management extension from the Visual Studio Marketplace.

Click the dropdown in the top left and select New feed:

New feed button

In the dialog:

  • Give the feed a name and a description (optional).
  • Choose who can read and contribute (or update) packages in your feed. The default selections give Team Build access so that continuous integration builds can add and update packages.
  • When you're done, choose Create.

New feed dialog

You can change these settings later by editing the feed.

Set up authentication

In order to talk to VSTS feeds, you'll need to put a token on your local machine that Maven can pick up and pass to VSTS.

  1. Navigate to the feed that you'd like to use and select Connect to feed.

    Connect to feed button in the upper-right of the page

  2. Open the Maven tab, click Generate Maven credentials, and copy the generated credentials. (images below)

  3. Maven pulls credentials from your settings.xml file:
    • The settings.xml file's path is "${user.home}/.m2/settings.xml" for Linux and "%USERPROFILE%/.m2/settings.xml" for Windows. If the file doesn't exist, create one now.

  4. Beneath the <settings> and <servers> tags in the file, paste the credentials you copied in Step 3 above.

Sample settings.xml:

<settings>
  <servers>
    <server>
      <id>yourAccount-visualstudio.com-yourFeedName</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Authorization</name>
            <!--The generated token expires on or before 7/19/2017-->
            <value>Basic Y2Fqb…</value>
          </property>
        </httpHeaders>
      </configuration>
    </server>
  </servers>
</settings>

NOTE: You can find more info on the settings.xml file in the settings.xml reference.

Publish a package

Publish Maven packages to a feed in Package Management to share them with your team and your organization.

In order to publish a Maven package, you'll need to have a Maven package to publish on your local box. 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 package's pom.xml. If you've just created an artifact, the pom.xml will be in the myFirstApp folder.
  3. From the connect to feed dialog in Team Services, copy the <repository> information. Paste it into your pom.xml twice: (See example above)
    • Between the <repositories> tags.
    • Between the <distributionManagement> tags.
  4. From the directory with your pom.xml, run the command mvn deploy. The Maven package should show up in your feed.

Sample pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>MyGroup</groupId>
   <artifactId>myFirstApp</artifactId>
   <packaging>jar</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>myFirstApp</name>
   <url>http://maven.apache.org</url>
   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
      </dependency>
   </dependencies>
   <repositories>
      <repository>
         <id>mseng-visualstudio.com-zcalvinmaven</id>
         <url>https://mseng.pkgs.visualstudio.com/_packaging/zCalvinMaven2/maven/v1</url>
         <releases>
            <enabled>true</enabled>
         </releases>
         <snapshots>
            <enabled>true</enabled>
         </snapshots>
      </repository>
   </repositories>
   <distributionManagement>
      <repository>
         <id>mseng-visualstudio.com-zcalvinmaven</id>
         <url>https://mseng.pkgs.visualstudio.com/_packaging/zCalvinMaven2/maven/v1</url>
         <releases>
            <enabled>true</enabled>
         </releases>
         <snapshots>
            <enabled>true</enabled>
         </snapshots>
      </repository>
   </distributionManagement>
</project>


See the Maven CLI docs for more publish options.

Install a package from your feed

Install Maven packages from your feed using the Maven client.

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

  1. Create a Maven package using the following command:

    mvn -B archetype:generate -DarchetypeGroupId="org.apache.maven.archetypes" -DgroupId="MyGroup" -DartifactId="mySecondApp"
    
  2. From the connect to feed dialog in Team Services, copy the <repository> information. Paste it into your pom.xml twice: (See example below)

    • Between the <repositories> tags.
    • Between the <distributionManagement> tags.
  3. In Team Services, go to the package you want to install, and copy the <dependency> XML.
  4. Paste the <dependency> information inside the <dependencies> tag of your POM.xml.
  5. Run mvn install from the directory containing your POM.xml.

See the Maven CLI docs for more install options.

Automate the process with continuous integration

You can use continuous integration systems like Team Build to automate the packing and publishing of your packages. To get started with continuous integration, see the Continuous delivery overview

You can also go directly to the Team Build + Maven guide.

What's next?

For more advanced topics, check out the content summary.