-[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)
- The `id` is what you [defined in `settings.xml`](#authenticate-to-the-package-registry-with-maven).
[defined in `settings.xml`](#add-the-package-registry-as-a-maven-remote).
- The `PROJECT_ID` is your project ID, which you can view on your project's home page.
- Replace `gitlab.example.com` with your domain name.
Replace `PROJECT_ID` with your project ID which can be found on the home page
- For retrieving artifacts, use either the
of your project.
[URL-encoded](../../../api/README.md#namespaced-path-encoding) path of the project
(like `group%2Fproject`) or the project's ID (like `42`). However, only the
If you have a self-managed GitLab installation, replace `gitlab.com` with your
project's ID can be used for publishing.
domain name.
NOTE: **Note:**
## Publish a package
For retrieving artifacts, you can use either the
[URL encoded](../../../api/README.md#namespaced-path-encoding) path of the project
(such as `group%2Fproject`) or the project's ID (such as `42`). However, only the
project's ID can be used for uploading.
## Uploading packages
After you have set up the [remote and authentication](#authenticate-to-the-package-registry-with-maven)
and [configured your project](#use-the-gitlab-endpoint-for-maven-packages),
publish a Maven artifact from your project.
Once you have set up the [remote and authentication](#add-the-package-registry-as-a-maven-remote)
### Publish by using Maven
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.
### Upload using Maven
To publish a package by using Maven:
```shell
```shell
mvn deploy
mvn deploy
```
```
If the deploy is successful, you should see the build success message again:
If the deploy is successful, the build success message should be displayed:
```shell
```shell
...
...
...
@@ -585,108 +551,112 @@ If the deploy is successful, you should see the build success message again:
...
@@ -585,108 +551,112 @@ If the deploy is successful, you should see the build success message again:
...
...
```
```
You should also see that the upload was uploaded to the correct registry:
The message should also show that the package was published to the correct location:
```shell
```shell
Uploading to gitlab-maven: https://gitlab.com/api/v4/projects/PROJECT_ID/packages/maven/com/mycompany/mydepartment/my-project/1.0-SNAPSHOT/my-project-1.0-20200128.120857-1.jar
Uploading to gitlab-maven: https://gitlab.example.com/api/v4/projects/PROJECT_ID/packages/maven/com/mycompany/mydepartment/my-project/1.0-SNAPSHOT/my-project-1.0-20200128.120857-1.jar
```
```
### Upload using Gradle
### Publish by using Gradle
Add the Gradle plugin [`maven-publish`](https://docs.gradle.org/current/userguide/publishing_maven.html) to the plugins section:
To publish a package by using Gradle:
```groovy
1. Add the Gradle plugin [`maven-publish`](https://docs.gradle.org/current/userguide/publishing_maven.html) to the plugins section:
value = gitLabPrivateToken // the variable resides in ~/.gradle/gradle.properties
credentials(HttpHeaderCredentials) {
}
name = "Private-Token"
authentication {
value = gitLabPrivateToken // the variable resides in ~/.gradle/gradle.properties
header(HttpHeaderAuthentication)
}
}
authentication {
}
header(HttpHeaderAuthentication)
}
}
}
}
```
}
}
```
Replace `PROJECT_ID` with your project ID which can be found on the home page
1. Replace `PROJECT_ID` with your project ID, which can be found on your project's home page.
of your project.
Run the publish task:
1. Run the publish task:
```shell
```shell
gradle publish
gradle publish
```
```
You can then navigate to your project's **Packages & Registries** page and see the uploaded
Now navigate to your project's **Packages & Registries** page and view the published artifacts.
artifacts or even delete them.
## Installing a package
## Install a package
Installing a package from the GitLab Package Registry requires that you set up
To install a package from the GitLab Package Registry, you must configure
the [remote and authentication](#add-the-package-registry-as-a-maven-remote)
the [remote and authenticate](#authenticate-to-the-package-registry-with-maven).
as above. Once this is completed, there are two ways to install a package.
When this is completed, there are two ways to install a package.
### Install using Maven with `mvn install`
### Use Maven with `mvn install`
Add the dependency manually to your project `pom.xml` file. To add the example
To install a package by using `mvn install`:
created above, the XML would look like:
```xml
1. Add the dependency manually to your project `pom.xml` file.
<dependency>
To add the example created earlier, the XML would be:
<groupId>com.mycompany.mydepartment</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
```
Then, inside your project, run the following:
```xml
<dependency>
<groupId>com.mycompany.mydepartment</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
```
```shell
1. In your project, run the following:
mvn install
```
```shell
mvn install
```
Provided everything is set up correctly, you should see the dependency
The message should show that the package is downloading from the Package Registry:
downloaded from the GitLab Package Registry:
```shell
```shell
Downloading from gitlab-maven: http://gitlab.com/api/v4/projects/PROJECT_ID/packages/maven/com/mycompany/mydepartment/my-project/1.0-SNAPSHOT/my-project-1.0-20200128.120857-1.pom
Downloading from gitlab-maven: http://gitlab.example.com/api/v4/projects/PROJECT_ID/packages/maven/com/mycompany/mydepartment/my-project/1.0-SNAPSHOT/my-project-1.0-20200128.120857-1.pom
```
```
### Install using Maven with `mvn dependency:get`
### Use Maven with `mvn dependency:get`
The second way to install packages is to use the Maven commands directly.
You can install packages by using the Maven commands directly.
Downloading from gitlab-maven: http://gitlab.example.com/api/v4/projects/PROJECT_ID/packages/maven/com/mycompany/mydepartment/my-project/1.0-SNAPSHOT/my-project-1.0-20200128.120857-1.pom
```
```
You should see the same downloading message confirming that the project was
retrieved from the GitLab Package Registry.
TIP: **Tip:**
TIP: **Tip:**
Both the XML block and Maven command are readily copy and pastable from the
In the GitLab UI, on the Package Registry page for Maven, you can view and copy these commands.
Package details page, allowing for quick and easy installation.
### Install using Gradle
### Use 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:
...
@@ -696,25 +666,25 @@ dependencies {
...
@@ -696,25 +666,25 @@ dependencies {
}
}
```
```
## Removing a package
## Remove a package
In the packages view of your project page, you can delete packages by clicking
For your project, go to **Packages & Registries > Package Registry**.
the red trash icons or by clicking the **Delete** button on the package details
page.
## Creating Maven packages with GitLab CI/CD
To remove a package, click the red trash icon or, from the package details, the **Delete** button.
Once you have your repository configured to use the GitLab Maven Repository,
## Create Maven packages with GitLab CI/CD
After you have configured your repository to use the Package Repository for Maven,
you can configure GitLab CI/CD to build new packages automatically.
you can configure GitLab CI/CD to build new packages automatically.
### Creating Maven packages with GitLab CI/CD using Maven
### Create Maven packages with GitLab CI/CD by using Maven
The example below shows how to create a new package each time the `master` branch
You can create a new package each time the `master` branch is updated.
is updated:
1. Create a `ci_settings.xml` file that serves as Maven's `settings.xml` file.
1. Create a `ci_settings.xml` file that serves as Maven's `settings.xml` file.
Add the server section with the same ID you defined in your `pom.xml` file.
For example, in our case it's `gitlab-maven`:
1. Add the `server` section with the same ID you defined in your `pom.xml` file.
- The user is `root`, because the job runs in a Docker container.
- Maven uses the configured CI [environment variables](../../../ci/variables/README.md#predefined-environment-variables).
### Creating Maven packages with GitLab CI/CD using Gradle
### Create Maven packages with GitLab CI/CD by using Gradle
The example below shows how to create a new package each time the `master` branch
You can create a 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"](#authenticate-with-a-ci-job-token-in-gradle).
1. Authenticate 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:
...
@@ -795,11 +765,13 @@ is updated:
...
@@ -795,11 +765,13 @@ is updated:
- master
- master
```
```
1. Push those files to your repository.
1. Commit files to your repository.
When the pipeline is successful, the package is created.
### Version validation
### Version validation
The version string is validated using the following regex.
The version string is validated by using the following regex.
```ruby
```ruby
\A(\.?[\w\+-]+\.?)+\z
\A(\.?[\w\+-]+\.?)+\z
...
@@ -827,7 +799,7 @@ When you set these options, all network requests are logged and a large amount o
...
@@ -827,7 +799,7 @@ When you set these options, all network requests are logged and a large amount o
### Useful Maven command-line options
### Useful Maven command-line options
There are some [Maven command-line options](https://maven.apache.org/ref/current/maven-embedder/cli.html)
There are some [Maven command-line options](https://maven.apache.org/ref/current/maven-embedder/cli.html)
that may be useful when performing tasks with GitLab CI/CD.
that you can use when performing tasks with GitLab CI/CD.
- File transfer progress can make the CI logs hard to read.
- File transfer progress can make the CI logs hard to read.
Option `-ntp,--no-transfer-progress` was added in
Option `-ntp,--no-transfer-progress` was added in
...
@@ -835,7 +807,7 @@ that may be useful when performing tasks with GitLab CI/CD.
...
@@ -835,7 +807,7 @@ that may be useful when performing tasks with GitLab CI/CD.
@@ -75,8 +75,8 @@ you do this, you can push your NPM package to your project using `npm publish`,
...
@@ -75,8 +75,8 @@ you do this, you can push your NPM package to your project using `npm publish`,
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#authenticate-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-in-maven).
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#publish-a-package) to your project.