Skip to content

Commit 5838846

Browse files
authored
Merge pull request #7936 from MicrosoftDocs/artifacts/425827
Publish artifacts - Gradle
2 parents 0ef4871 + 46c002d commit 5838846

File tree

1 file changed

+22
-179
lines changed

1 file changed

+22
-179
lines changed
Lines changed: 22 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -1,214 +1,57 @@
11
---
2-
title: Publish artifacts using Gradle
2+
title: Publish artifacts with Gradle
33
description: Learn how to connect to a feed and publish your packages with Gradle.
44
ms.service: azure-devops-artifacts
5-
ms.topic: conceptual
6-
ms.date: 10/16/2024
5+
ms.topic: how-to
6+
ms.date: 05/12/2025
77
ms.author: rabououn
88
author: ramiMSFT
99
monikerRange: '<= azure-devops'
1010
"recommendations": "true"
1111
---
1212

13-
# Publish artifacts with Gradle
13+
# Publish packages - Gradle
1414

1515
[!INCLUDE [version-lt-eq-azure-devops](../../includes/version-lt-eq-azure-devops.md)]
1616

17-
With Azure Artifacts, you can efficiently manage your dependencies from a single feed, storing various types of packages in one place. Azure Artifacts enables developers to publish and consume packages from different sources, and sharing them according to the feed's visibility settings. In this article, you'll learn how to connect to an Azure Artifacts feed and publish your packages using Gradle.
17+
Azure Artifacts enables developers to manage all their dependencies in one place by storing multiple package types in a single feed. This article walks you through connecting to an Azure Artifacts feed and publishing packages using Gradle.
1818

1919
## Prerequisites
2020

21-
- Create an Azure DevOps [organization](../../organizations/accounts/create-organization.md) and a [project](../../organizations/projects/create-project.md#create-a-project) if you haven't already.
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> - Download and install [Gradle](https://docs.gradle.org/current/userguide/installation.html). |
2224

23-
- [Create a feed](../get-started-maven.md#create-a-feed) if you don't have one already.
25+
## Create a feed
2426

25-
- Download and install [Gradle](https://docs.gradle.org/current/userguide/installation.html).
26-
27-
- Install the [Java Development Kit (JDK)](https://jdk.java.net/) version 8 or higher.
28-
29-
## Create a personal access token
30-
31-
To authenticate with your feed, you must first create a personal access token with packaging *Read & Write* scopes:
27+
Azure Artifacts recommends using one feed for consuming packages and a separate one for publishing your internal packages. If you already have a feed, you can skip this step. Otherwise, follow these steps to create a new feed:
3228

3329
1. Sign in to your Azure DevOps organization, and then navigate to your project.
3430

35-
1. Select **User settings**, and then select **Personal access tokens**.
36-
37-
:::image type="content" source="media/create-pat.png" alt-text="A screenshot showing how to locate the personal access token button.":::
38-
39-
1. Select **New Token** and fill out the required fields. Be sure to select the **Packaging** > **Read & write** scope.
40-
41-
1. Select **Create** when you're done. Copy your token and save it in a secure location, as you'll need it for the next step.
42-
43-
:::image type="content" source="media/gradle-pat.png" alt-text="A screenshot demonstrating how to create a new personal access token with packaging read & write scopes.":::
44-
45-
## Project setup
46-
47-
# [Gradle 8.2 and above](#tab/newer)
48-
49-
Before setting up your project, ensure Gradle is installed and that you've added the Maven Settings plugin to your *build.gradle* file as follows:
50-
51-
```groovy
52-
plugins {
53-
id 'maven-publish'
54-
}
55-
```
56-
57-
#### Configure build.gradle
58-
59-
1. If a *build.gradle* file doesn't exist in the root of your project, create a new file and name it: *build.gradle*.
60-
61-
1. Add the following section to your *build.gradle* file within both the **repositories** and **publishing.repositories** containers:
62-
63-
```groovy
64-
maven {
65-
url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1' //for organization-scoped feeds use this format: 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/maven/v1'
66-
name '<FEED_NAME>'
67-
credentials(PasswordCredentials)
68-
authentication {
69-
basic(BasicAuthentication)
70-
}
71-
}
72-
```
73-
74-
Here's an example of what your *build.gradle* file should look like:
75-
76-
```groovy
77-
repositories {
78-
mavenCentral()
79-
80-
maven {
81-
url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1' //for organization-scoped feeds use this format: 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/maven/v1'
82-
name '<FEED_NAME>'
83-
credentials(PasswordCredentials)
84-
authentication {
85-
basic(BasicAuthentication)
86-
}
87-
}
88-
}
89-
90-
publishing {
91-
publications {
92-
library(MavenPublication) {
93-
from components.java
94-
}
95-
}
96-
97-
repositories {
98-
maven {
99-
url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1' //for organization-scoped feeds use this format: 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/maven/v1'
100-
name '<FEED_NAME>'
101-
credentials(PasswordCredentials)
102-
authentication {
103-
basic(BasicAuthentication)
104-
}
105-
}
106-
}
107-
}
108-
```
109-
110-
#### Configure gradle.properties
111-
112-
1. Open the *gradle.properties* file located in the *.gradle* directory of your home folder (~/.gradle/gradle.properties). If the file doesn't exist, create a new one.
113-
114-
1. Add the following snippet, replacing the placeholders with your feed name, organization name, and the personal access token you created earlier.
31+
1. Select **Artifacts**, then select **Create Feed**.
11532

116-
```
117-
# Substitute FEED_NAME with the same name specified as the 'name' of the maven repository in build.gradle.
118-
# The value of the username is arbitrary but should not be blank.
119-
[FEED_NAME]Username=[ORGANIZATION_NAME]
120-
[FEED_NAME]Password=[PERSONAL_ACCESS_TOKEN]
121-
```
122-
123-
# [Older versions](#tab/older)
33+
1. Provide a **Name** for your feed and set its **Visibility**, then select a **Scope** for your feed. If you'd like to include packages from public registries, check the **Upstream sources** checkbox.
12434

125-
Before setting up your project, ensure Gradle is installed and that you've added the Maven Settings plugin to your *build.gradle* file as follows:
35+
1. Select **Create** when you're done.
12636

127-
```groovy
128-
plugins {
129-
id 'net.linguica.maven-settings' version '0.5'
130-
id 'maven-publish'
131-
}
132-
```
37+
## Publish packages
13338

134-
#### Configure build.gradle
39+
1. If you haven't authenticated with your feed yet, follow the steps in [Project setup](project-setup-gradle.md) to set up your config files and authenticate with your feed.
13540

136-
1. If a *build.gradle* file doesn't exist in the root of your project, create a new file and name it: *build.gradle*.
41+
1. In your project directory, run the following command to publish your package:
13742

138-
1. Add the following section to your *build.gradle* file within both the **repositories** and **publishing.repositories** containers:
139-
140-
```groovy
141-
maven {
142-
url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1' //for organization-scoped feeds use this format: 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/maven/v1'
143-
name '<FEED_NAME>'
144-
authentication {
145-
basic(BasicAuthentication)
146-
}
147-
}
14843
```
149-
150-
Here's an example of what your *build.gradle* file should look like:
151-
152-
```groovy
153-
publishing {
154-
publications {
155-
library(MavenPublication) {
156-
from components.java
157-
}
158-
}
159-
160-
// Repositories to publish artifacts
161-
repositories {
162-
maven {
163-
url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1' //for organization-scoped feeds use this format: 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/maven/v1'
164-
name '<FEED_NAME>'
165-
authentication {
166-
basic(BasicAuthentication)
167-
}
168-
}
169-
}
170-
}
171-
172-
// Repositories to fetch dependencies
173-
repositories {
174-
maven {
175-
url 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/maven/v1' //for organization-scoped feeds use this format: 'https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/maven/v1'
176-
name '<FEED_NAME>'
177-
authentication {
178-
basic(BasicAuthentication)
179-
}
180-
}
181-
}
182-
```
183-
184-
#### Configure settings.xml
185-
186-
1. Open the *settings.xml* file located in the *.m2* directory of your home folder (typically found at *~/.m2/settings.xml* on macOS and Linux, and at *Users\<YourUsername>\.m2\settings.xml* on Windows). If the file doesn't exist, you can create a new one.
187-
188-
1. Add the following snippet, replacing the placeholders with your feed name, organization name, and the personal access token you created earlier.
189-
190-
```xml
191-
<server>
192-
<id>[FEED_NAME]</id>
193-
<username>[ORGANIZATION_NAME]</username>
194-
<password>[PERSONAL_ACCESS_TOKEN]</password>
195-
</server>
196-
```
197-
198-
---
199-
200-
## Publish your packages
201-
202-
1. Run the following command in your project directory to publish your package to your feed:
203-
204-
```command
20544
gradle publish
20645
```
20746
208-
:::image type="content" source="media/publish-package-gradle.png" alt-text="A screenshot displaying a package successfully published to the feed.":::
47+
1. Once published, navigate to your feed. You should see your packages listed, as shown in the example below:
48+
49+
:::image type="content" source="media/publish-package-gradle.png" alt-text="A screenshot displaying a package successfully published to the feed.":::
20950
21051
## Related content
21152
212-
- [Use packages from Maven Central](upstream-sources.md)
21353
- [Restore Maven packages](./install.md)
54+
55+
- [Use packages from Maven Central](upstream-sources.md)
56+
21457
- [Use packages from Google Maven Repository](google-maven.md)

0 commit comments

Comments
 (0)