| title | Connect to an Azure Artifacts feed - Gradle |
|---|---|
| description | Learn how to set up your project and connect to an Azure Artifacts feed with Gradle. |
| ms.service | azure-devops-artifacts |
| ms.topic | how-to |
| ms.author | rabououn |
| author | ramiMSFT |
| ms.date | 05/08/2025 |
| monikerRange | <=azure-devops |
| recommendations | true |
[!INCLUDE version-lt-eq-azure-devops]
Azure Artifacts enables developers to manage project dependencies from a single feed while controlling who can view, publish, or install packages. This article walks you through setting up your project and connecting to an Azure Artifacts feed using Gradle.
| Product | Requirements |
|---|---|
| Azure DevOps | - An Azure DevOps organization. - An Azure DevOps project. - An Azure Artifacts feed. - Download and install Gradle. |
-
Make sure you've installed Gradle, then add the Maven Settings plugin to your build.gradle file:
plugins { id 'maven-publish' } -
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Artifacts, select your feed from the dropdown menu, and then select Connect to feed.
-
Select Gradle from the left navigation pane.
-
If you don't have a build.gradle file in the root of your project, create one and name it: build.gradle.
-
Add the snippet from the Project setup section to your build.gradle file under both the repositories and publishing.repositories blocks. Your file should look similar to the following:
repositories { mavenCentral() maven { url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1' name '<FEED_NAME>' credentials(PasswordCredentials) authentication { basic(BasicAuthentication) } } } publishing { publications { library(MavenPublication) { from components.java } } repositories { maven { url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1' name '<FEED_NAME>' credentials(PasswordCredentials) authentication { basic(BasicAuthentication) } } } } -
Generate a Personal Access Token with Packaging > Read & write scopes, Copy it to your clipboard; you’ll use it in the next step.
-
Open the gradle.properties file in the .gradle directory of your home folder (~/.gradle/gradle.properties). If it doesn’t exist, create a new file, then add the snippet from the Project setup section replacing the placeholder with the personal access token you just created:
## Substitute FEED_NAME with the same name used in your build.gradle ## The username value can be any non-blank string [FEED_NAME]Username=[ORGANIZATION_NAME] [FEED_NAME]Password=[PERSONAL_ACCESS_TOKEN]
-
Make sure you've installed Gradle, then add the Maven Settings plugin to your build.gradle file:
plugins { id 'net.linguica.maven-settings' version '0.5' id 'maven-publish' } -
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Artifacts, select your feed from the dropdown menu, and then select Connect to feed.
-
Select Gradle from the left navigation pane.
-
If you don't have a build.gradle file in the root of your project, create one and name it: build.gradle.
-
Add the snippet from the Project setup section to your build.gradle file under both the repositories and publishing.repositories blocks. Your file should look similar to the following:
publishing { publications { library(MavenPublication) { from components.java } } repositories { maven { url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1' name '<FEED_NAME>' authentication { basic(BasicAuthentication) } } } } repositories { maven { url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1' name '<FEED_NAME>' authentication { basic(BasicAuthentication) } } } -
Generate a Personal Access Token with Packaging > Read & write scopes, Copy it to your clipboard; you’ll use it in the next step.
-
Open the settings.xml file in the .m2 directory of your home folder (~/.m2/settings.xml - MacOS/Linux, Users<YourUsername>.m2\settings.xml - Windows). If it doesn’t exist, create a new file, then add the following snippet, replacing the placeholders with your feed name, organization name, and the personal access token you created earlier.
<server> <id>[FEED_NAME]</id> <username>[ORGANIZATION_NAME]</username> <password>[PERSONAL_ACCESS_TOKEN]</password> </server>