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.
### Installing Maven
The required minimum versions are:
...
...
@@ -96,6 +98,110 @@ your project has been set up successfully:
You should see a new directory where you ran this command matching your
`DartifactId` parameter (in this case it should be `my-project`).
## Getting started with Gradle
This section will cover installing Gradle and initializing a Java project. This is a
quickstart to help if you're new to Gradle. If you're already
using Gradle and understand how to build your own packages, move onto the
[defined in `settings.xml`](#adding-the-gitlab-package-registry-as-a-maven-remote).
...
...
@@ -314,6 +499,17 @@ the `distributionManagement` section:
</distributionManagement>
```
The corresponding repositories section in Gradle would look like:
```groovy
repositories {
maven {
url "https://gitlab.com/api/v4/packages/maven"
name "GitLab"
}
}
```
The `id` must be the same with what you
[defined in `settings.xml`](#adding-the-gitlab-package-registry-as-a-maven-remote).
...
...
@@ -333,7 +529,9 @@ project's ID can be used for uploading.
Once you have set up the [remote and authentication](#adding-the-gitlab-package-registry-as-a-maven-remote)
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.
### Upload using Maven
```shell
mvn deploy
...
...
@@ -353,6 +551,50 @@ You should also see that the upload was uploaded to the correct registry:
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
```
### Upload using Gradle
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
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
```
Replace `PROJECT_ID` with your project ID which can be found on the home page
of your project.
Run the publish task:
```shell
gradle publish
```
You can then navigate to your project's **Packages** page and see the uploaded
artifacts or even delete them.
...
...
@@ -362,7 +604,7 @@ 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)
as above. Once this is completed, there are two ways for installaing a package.
### Install with `mvn install`
### Install using Maven with `mvn install`
Add the dependency manually to your project `pom.xml` file. To add the example
created above, the XML would look like:
...
...
@@ -388,7 +630,7 @@ downloaded from the GitLab Package Registry:
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
```
### Install with `mvn dependency:get`
#### Install with `mvn dependency:get`
The second way to install packages is to use the Maven commands directly.
Inside your project directory, run:
...
...
@@ -404,6 +646,16 @@ TIP: **Tip:**
Both the XML block and Maven command are readily copy and pastable from the
Package details page, allowing for quick and easy installation.
### Install using Gradle
Add a [dependency](https://docs.gradle.org/current/userguide/declaring_dependencies.html) to build.gradle in the dependencies section:
### Creating Maven packages with GitLab CI/CD using Gradle
The example below shows how to create a new package each time the `master` branch
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. Add a `deploy` job to your `.gitlab-ci.yml` file:
```yaml
deploy:
image: gradle:latest
script:
- 'gradle publish'
only:
- master
```
1. Push those files to your repository.
The next time the `deploy` job runs, it will copy `ci_settings.xml` to the
user's home location (in this case the user is `root` since it runs in a
Docker container), and Maven will use the configured CI