-[Container Registry](../user/packages/container_registry/index.md)(`$CI_REGISTRY_PASSWORD` is actually `$CI_JOB_TOKEN`, but this may change in the future)
-[Container Registry](../user/packages/container_registry/index.md)(`$CI_REGISTRY_PASSWORD` is actually `$CI_JOB_TOKEN`, but this may change in the future)
info:To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
info:To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
---
---
# GitLab Maven Repository
# Maven packages in the Package Repository
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/5811) in [GitLab Premium](https://about.gitlab.com/pricing/) 11.3.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/5811) in [GitLab Premium](https://about.gitlab.com/pricing/) 11.3.
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/221259) to GitLab Core in 13.3.
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/221259) to GitLab Core in 13.3.
With the GitLab [Maven](https://maven.apache.org) Repository, every
Publish [Maven](https://maven.apache.org) artifacts in your project’s Package Registry.
project can have its own space to store its Maven artifacts.
Then, install the packages whenever you need to use them as a dependency.
Maven repositories work well with Gradle, too. Move onto [getting started with Gradle](#getting-started-with-gradle) if you want to setup a Gradle project.
[defined in `settings.xml`](#adding-the-gitlab-package-registry-as-a-maven-remote).
[defined in `settings.xml`](#add-the-package-registry-as-a-maven-remote).
Replace `PROJECT_ID` with your project ID which can be found on the home page
Replace `PROJECT_ID` with your project ID which can be found on the home page
of your project.
of your project.
...
@@ -452,7 +432,7 @@ domain name.
...
@@ -452,7 +432,7 @@ domain name.
NOTE: **Note:**
NOTE: **Note:**
For retrieving artifacts, you can use either the
For retrieving artifacts, you can use either the
[URL encoded](../../../api/README.md#namespaced-path-encoding) path of the project
[URL encoded](../../../api/README.md#namespaced-path-encoding) path of the project
(e.g., `group%2Fproject`) or the project's ID (e.g., `42`). However, only the
(such as `group%2Fproject`) or the project's ID (such as `42`). However, only the
project's ID can be used for uploading.
project's ID can be used for uploading.
### Group level Maven endpoint
### Group level Maven endpoint
...
@@ -505,7 +485,7 @@ repositories {
...
@@ -505,7 +485,7 @@ repositories {
```
```
The `id` must be the same with what you
The `id` must be the same with what you
[defined in `settings.xml`](#adding-the-gitlab-package-registry-as-a-maven-remote).
[defined in `settings.xml`](#add-the-package-registry-as-a-maven-remote).
Replace `my-group` with your group name and `PROJECT_ID` with your project ID
Replace `my-group` with your group name and `PROJECT_ID` with your project ID
which can be found on the home page of your project.
which can be found on the home page of your project.
...
@@ -516,7 +496,7 @@ domain name.
...
@@ -516,7 +496,7 @@ domain name.
NOTE: **Note:**
NOTE: **Note:**
For retrieving artifacts, you can use either the
For retrieving artifacts, you can use either the
[URL encoded](../../../api/README.md#namespaced-path-encoding) path of the group
[URL encoded](../../../api/README.md#namespaced-path-encoding) path of the group
(e.g., `group%2Fsubgroup`) or the group's ID (e.g., `12`).
(such as `group%2Fsubgroup`) or the group's ID (such as `12`).
### Instance level Maven endpoint
### Instance level Maven endpoint
...
@@ -571,7 +551,7 @@ repositories {
...
@@ -571,7 +551,7 @@ repositories {
```
```
The `id` must be the same with what you
The `id` must be the same with what you
[defined in `settings.xml`](#adding-the-gitlab-package-registry-as-a-maven-remote).
[defined in `settings.xml`](#add-the-package-registry-as-a-maven-remote).
Replace `PROJECT_ID` with your project ID which can be found on the home page
Replace `PROJECT_ID` with your project ID which can be found on the home page
of your project.
of your project.
...
@@ -582,12 +562,12 @@ domain name.
...
@@ -582,12 +562,12 @@ domain name.
NOTE: **Note:**
NOTE: **Note:**
For retrieving artifacts, you can use either the
For retrieving artifacts, you can use either the
[URL encoded](../../../api/README.md#namespaced-path-encoding) path of the project
[URL encoded](../../../api/README.md#namespaced-path-encoding) path of the project
(e.g., `group%2Fproject`) or the project's ID (e.g., `42`). However, only the
(such as `group%2Fproject`) or the project's ID (such as `42`). However, only the
project's ID can be used for uploading.
project's ID can be used for uploading.
## Uploading packages
## Uploading packages
Once you have set up the [remote and authentication](#adding-the-gitlab-package-registry-as-a-maven-remote)
Once you have set up the [remote and authentication](#add-the-package-registry-as-a-maven-remote)
and [configured your project](#configuring-your-project-to-use-the-gitlab-maven-repository-url),
and [configured your project](#configuring-your-project-to-use-the-gitlab-maven-repository-url),
test to upload a Maven artifact from a project of yours.
test to upload a Maven artifact from a project of yours.
...
@@ -661,7 +641,7 @@ artifacts or even delete them.
...
@@ -661,7 +641,7 @@ artifacts or even delete them.
## Installing a package
## Installing a package
Installing a package from the GitLab Package Registry requires that you set up
Installing a package from the GitLab Package Registry requires that you set up
the [remote and authentication](#adding-the-gitlab-package-registry-as-a-maven-remote)
the [remote and authentication](#add-the-package-registry-as-a-maven-remote)
as above. Once this is completed, there are two ways to install a package.
as above. Once this is completed, there are two ways to install a package.
### Install using Maven with `mvn install`
### Install using Maven with `mvn install`
...
@@ -708,7 +688,7 @@ Package details page, allowing for quick and easy installation.
...
@@ -708,7 +688,7 @@ Package details page, allowing for quick and easy installation.
### Install using Gradle
### Install using Gradle
Add a [dependency](https://docs.gradle.org/current/userguide/declaring_dependencies.html) to build.gradle in the dependencies section:
Add a [dependency](https://docs.gradle.org/current/userguide/declaring_dependencies.html) to `build.gradle` in the dependencies section:
```groovy
```groovy
dependencies {
dependencies {
...
@@ -802,7 +782,7 @@ Docker container), and Maven uses the configured CI
...
@@ -802,7 +782,7 @@ Docker container), and Maven uses the configured CI
The example below shows how to create a new package each time the `master` branch
The example below shows how to create a new package each time the `master` branch
is updated:
is updated:
1. Make sure you use the Job-Token authentication as described in ["Authenticating with a CI job token in Gradle"](#authenticating-with-a-ci-job-token-in-gradle).
1. Make sure you use the Job-Token authentication as described in ["Authenticating with a CI job token in Gradle"](#authenticate-with-a-ci-job-token-in-gradle).
1. Add a `deploy` job to your `.gitlab-ci.yml` file:
1. Add a `deploy` job to your `.gitlab-ci.yml` file:
@@ -26,8 +26,8 @@ point them at the same project on GitLab.
...
@@ -26,8 +26,8 @@ point them at the same project on GitLab.
There are a few reasons you might want to publish all your packages to one project on GitLab:
There are a few reasons you might want to publish all your packages to one project on GitLab:
1. You want to publish your packages on GitLab, but to a project that is different from where your code is stored.
1. You want to publish your packages on GitLab, but to a project that is different from where your code is stored.
1. You would like to group packages together in ways that make sense for your usage (all NPM packages in one project,
1. You would like to group packages together in ways that make sense for your usage (such as all NPM packages in one project,
all packages being used by a specific department in one project, all private packages in one project, etc.)
all packages being used by a specific department in one project, or all private packages in one project)
1. You want to use one remote for all of your packages when installing them into other projects.
1. You want to use one remote for all of your packages when installing them into other projects.
1. You would like to migrate your packages to a single place on GitLab from a third-party package registry and do not
1. You would like to migrate your packages to a single place on GitLab from a third-party package registry and do not
want to worry about setting up separate projects for each package.
want to worry about setting up separate projects for each package.
...
@@ -44,7 +44,7 @@ Let's take a look at how you might create a public place to hold all of your pub
...
@@ -44,7 +44,7 @@ Let's take a look at how you might create a public place to hold all of your pub
### Create a project
### Create a project
First, create a new project on GitLab. It does not have to have any code or content. Make note of the project ID
First, create a new project on GitLab. It does not have to have any code or content. Make note of the project ID
displayed on the project overview page, as you will need this later.
displayed on the project overview page for use later in this process.
### Create an access token
### Create an access token
...
@@ -67,15 +67,15 @@ If you are using NPM, this involves creating an `.npmrc` file and adding the app
...
@@ -67,15 +67,15 @@ If you are using NPM, this involves creating an `.npmrc` file and adding the app
to your project using your project ID, then adding a section to your `package.json` file with a similar URL.
to your project using your project ID, then adding a section to your `package.json` file with a similar URL.
Follow
Follow
the instructions in the [GitLab NPM Registry documentation](../npm_registry/index.md#authenticating-to-the-gitlab-npm-registry). Once
the instructions in the [GitLab NPM Registry documentation](../npm_registry/index.md#authenticating-to-the-gitlab-npm-registry). After
you do this, you will be able to push your NPM package to your project using `npm publish`, as described in the
you do this, you can push your NPM package to your project using `npm publish`, as described in the
[uploading packages](../npm_registry/index.md#uploading-packages) section of the docs.
[uploading packages](../npm_registry/index.md#uploading-packages) section of the docs.
#### Maven
#### Maven
If you are using Maven, this involves updating your `pom.xml` file with distribution sections, including the
If you are using Maven, this involves updating your `pom.xml` file with distribution sections, including the
appropriate URL for your project, as described in the [GitLab Maven Repository documentation](../maven_repository/index.md#project-level-maven-endpoint).
appropriate URL for your project, as described in the [GitLab Maven Repository documentation](../maven_repository/index.md#project-level-maven-endpoint).
Then, you need to add a `settings.xml` file and [include your access token](../maven_repository/index.md#authenticating-with-a-personal-access-token).
Then, you need to add a `settings.xml` file and [include your access token](../maven_repository/index.md#authenticate-with-a-personal-access-token).
Now you can [deploy Maven packages](../maven_repository/index.md#uploading-packages) to your project.
Now you can [deploy Maven packages](../maven_repository/index.md#uploading-packages) to your project.
#### Conan
#### Conan
...
@@ -83,7 +83,7 @@ Now you can [deploy Maven packages](../maven_repository/index.md#uploading-packa
...
@@ -83,7 +83,7 @@ Now you can [deploy Maven packages](../maven_repository/index.md#uploading-packa
For Conan, first you need to add GitLab as a Conan registry remote. Follow the instructions in the [GitLab Conan Repository docs](../conan_repository/index.md#add-the-package-registry-as-a-conan-remote)
For Conan, first you need to add GitLab as a Conan registry remote. Follow the instructions in the [GitLab Conan Repository docs](../conan_repository/index.md#add-the-package-registry-as-a-conan-remote)
to do so. Then, create your package using the plus-separated (`+`) project path as your Conan user. For example,
to do so. Then, create your package using the plus-separated (`+`) project path as your Conan user. For example,
if your project is located at `https://gitlab.com/foo/bar/my-proj`, then you can [create your Conan package](../conan_repository/index.md)
if your project is located at `https://gitlab.com/foo/bar/my-proj`, then you can [create your Conan package](../conan_repository/index.md)
using `conan create . foo+bar+my-proj/channel`, where `channel` is your package channel (`stable`, `beta`, etc.). Once your package
using `conan create . foo+bar+my-proj/channel`, where `channel` is your package channel (such as `stable` or `beta`). After your package
is created, you are ready to [upload your package](../conan_repository/index.md#publish-a-conan-package) depending on your final package recipe. For example:
is created, you are ready to [upload your package](../conan_repository/index.md#publish-a-conan-package) depending on your final package recipe. For example: