Skip to content

Commit 18dfb86

Browse files
authored
Merge pull request #7925 from MicrosoftDocs/artifacts/425825
Gradle auth
2 parents 0c0b87b + 647509b commit 18dfb86

File tree

2 files changed

+172
-3
lines changed

2 files changed

+172
-3
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
title: Connect to an Azure Artifacts feed - Gradle
3+
description: Learn how to set up your project and connect to an Azure Artifacts feed with Gradle.
4+
ms.service: azure-devops-artifacts
5+
ms.topic: how-to
6+
ms.author: rabououn
7+
author: ramiMSFT
8+
ms.date: 05/08/2025
9+
monikerRange: '<= azure-devops'
10+
"recommendations": "true"
11+
---
12+
13+
# Connect to an Azure Artifacts feed - Gradle
14+
15+
[!INCLUDE [version-lt-eq-azure-devops](../../includes/version-lt-eq-azure-devops.md)]
16+
17+
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.
18+
19+
## Prerequisites
20+
21+
| **Product** | **Requirements** |
22+
|--------------------|----------------------------------------|
23+
| **Azure DevOps** | - An Azure DevOps [organization](../../organizations/accounts/create-organization.md).<br>- An Azure DevOps [project](../../organizations/projects/create-project.md).<br> - An Azure Artifacts [feed](../get-started-nuget.md#create-feed).<br> - Download and install [Gradle](https://docs.gradle.org/current/userguide/installation.html). |
24+
25+
## Project setup
26+
27+
# [Gradle 8.2 and above](#tab/newerversions)
28+
29+
1. Make sure you've installed Gradle, then add the *Maven Settings plugin* to your *build.gradle* file:
30+
31+
```groovy
32+
plugins {
33+
id 'maven-publish'
34+
}
35+
```
36+
37+
1. Sign in to your Azure DevOps organization, and then navigate to your project.
38+
39+
1. Select **Artifacts**, select your feed from the dropdown menu, and then select **Connect to feed**.
40+
41+
1. Select **Gradle** from the left navigation pane.
42+
43+
1. If you don't have a *build.gradle* file in the root of your project, create one and name it: *build.gradle*.
44+
45+
1. 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:
46+
47+
```groovy
48+
repositories {
49+
mavenCentral()
50+
51+
maven {
52+
url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1'
53+
name '<FEED_NAME>'
54+
credentials(PasswordCredentials)
55+
authentication {
56+
basic(BasicAuthentication)
57+
}
58+
}
59+
}
60+
61+
publishing {
62+
publications {
63+
library(MavenPublication) {
64+
from components.java
65+
}
66+
}
67+
68+
repositories {
69+
maven {
70+
url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1'
71+
name '<FEED_NAME>'
72+
credentials(PasswordCredentials)
73+
authentication {
74+
basic(BasicAuthentication)
75+
}
76+
}
77+
}
78+
}
79+
```
80+
81+
1. Generate a [Personal Access Token](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md#create-a-pat) with **Packaging** > **Read & write** scopes, Copy it to your clipboard; you’ll use it in the next step.
82+
83+
1. 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:
84+
85+
```
86+
## Substitute FEED_NAME with the same name used in your build.gradle
87+
## The username value can be any non-blank string
88+
[FEED_NAME]Username=[ORGANIZATION_NAME]
89+
[FEED_NAME]Password=[PERSONAL_ACCESS_TOKEN]
90+
```
91+
92+
# [Older versions](#tab/olderversions)
93+
94+
1. Make sure you've installed Gradle, then add the *Maven Settings plugin* to your *build.gradle* file:
95+
96+
```groovy
97+
plugins {
98+
id 'net.linguica.maven-settings' version '0.5'
99+
id 'maven-publish'
100+
}
101+
```
102+
103+
1. Sign in to your Azure DevOps organization, and then navigate to your project.
104+
105+
1. Select **Artifacts**, select your feed from the dropdown menu, and then select **Connect to feed**.
106+
107+
1. Select **Gradle** from the left navigation pane.
108+
109+
1. If you don't have a *build.gradle* file in the root of your project, create one and name it: *build.gradle*.
110+
111+
1. 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:
112+
113+
```groovy
114+
publishing {
115+
publications {
116+
library(MavenPublication) {
117+
from components.java
118+
}
119+
}
120+
121+
repositories {
122+
maven {
123+
url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1'
124+
name '<FEED_NAME>'
125+
authentication {
126+
basic(BasicAuthentication)
127+
}
128+
}
129+
}
130+
}
131+
132+
repositories {
133+
maven {
134+
url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1'
135+
name '<FEED_NAME>'
136+
authentication {
137+
basic(BasicAuthentication)
138+
}
139+
}
140+
}
141+
```
142+
143+
1. Generate a [Personal Access Token](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md#create-a-pat) with **Packaging** > **Read & write** scopes, Copy it to your clipboard; you’ll use it in the next step.
144+
145+
1. 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.
146+
147+
```xml
148+
<server>
149+
<id>[FEED_NAME]</id>
150+
<username>[ORGANIZATION_NAME]</username>
151+
<password>[PERSONAL_ACCESS_TOKEN]</password>
152+
</server>
153+
```
154+
155+
---
156+
157+
## Related content
158+
159+
- [Publish artifacts with Gradle](publish-with-gradle.md)
160+
161+
- [Restore Maven packages](install.md)
162+
163+
- [Use packages from Maven Central](upstream-sources.md)

docs/artifacts/toc.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@
9898
href: npm/npm-audit.md
9999
- name: Maven
100100
items:
101-
- name: Project setup
102-
displayName: maven pom, maven artifacts, maven packages, maven authentication
101+
- name: Project setup - Maven
102+
displayName: maven, pom, artifacts, package
103103
href: maven/project-setup-maven.md
104+
- name: Project setup - Gradle
105+
displayName: Maven, Gradle
106+
href: maven/project-setup-gradle.md
104107
- name: Publish artifacts with Gradle
105108
displayName: gradle, publish
106109
href: maven/publish-with-gradle.md
@@ -163,9 +166,12 @@
163166
href: npm/npm-audit.md
164167
- name: Maven
165168
items:
166-
- name: Project setup
169+
- name: Project setup - Maven
167170
displayName: maven pom, maven artifacts, maven packages, maven authentication
168171
href: maven/project-setup-maven.md
172+
- name: Project setup - Gradle
173+
displayName: Maven, Gradle
174+
href: maven/project-setup-gradle.md
169175
- name: Restore Maven packages
170176
displayName: maven, restore, install
171177
href: maven/install.md

0 commit comments

Comments
 (0)