共用方式為


Get started with Maven packages and Azure Artifacts

TFS 2018

This quickstart will guide you through setting up your Maven project to connect to Azure Artifacts feeds and publish and download your Maven packages.

Prerequisites

Set up authentication

  1. Select Packages, and then select Connect to Feed.

    A screenshot showing how to connect to a feed in TFS.

  2. Select Maven.

  3. If this is the first time using Azure Artifacts with Maven, select Get the tools to download and install Maven.

  4. Follow the instructions in the Project setup to set up your pom.xml and settings.xml files. If your settings.xml file is shared within your team, you can use Maven to encrypt your passwords.

    A screenshot showing how to set up your project.

Tip

If you are using Maven task, set the mavenAuthenticateFeed argument to true to automatically authenticate with your Maven feed.

Publish artifacts

  1. If you don't have a Maven package yet, you can create one by running the following command:

    mvn -B archetype:generate -DarchetypeGroupId="org.apache.maven.archetypes" -DgroupId="MyGroup" -DartifactId="myFirstApp"
    

    If you get the following error: You must specify a valid lifecycle phase or a goal (..), follow the steps below to add a goal to your configuration:

    Right click on your project, select Run as > Maven Build. Enter package in the Goals text box, and then select Run.

  2. Navigate to the path of your pom.xml file and run the following commands to build and deploy your Maven artifact:

    mvn build
    mvn deploy
    

If you get the following error: Unknown lifecycle phase "build"(...) when you run mvn build, you can use Eclipse IDE to build your maven project as follows:

  1. Right click on your project.

  2. Select Run as, and then select Maven Build....

  3. Write package in the Goals text box.

  4. Select Run.

    A screenshot showing how to build a project using Eclipse.

If you want to publish a third-party artifact, you can use the deploy:deploy-file mojo. This can be used with or without a POM file to deploy your packages.

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

Note

If your organization is using a firewall or a proxy server, make sure you allow Azure Artifacts Domain URLs and IP addresses.

Install artifacts

  1. Select Packages, and then select the package you want to install and copy the <dependency> snippet.

  2. Open your pom.xml file and paste your code inside the <dependencies> tag.

  3. Run mvn install from the same path as your pom.xml file.