Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/user/packages/maven_repository/index.md')
-rw-r--r--doc/user/packages/maven_repository/index.md145
1 files changed, 139 insertions, 6 deletions
diff --git a/doc/user/packages/maven_repository/index.md b/doc/user/packages/maven_repository/index.md
index 957374245d2..ec56255999a 100644
--- a/doc/user/packages/maven_repository/index.md
+++ b/doc/user/packages/maven_repository/index.md
@@ -1,7 +1,7 @@
---
stage: Package
group: Package
-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/#assignments
+info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
---
# Maven packages in the Package Repository **(FREE)**
@@ -168,7 +168,7 @@ published to the GitLab Package Registry.
Enter selection (default: Groovy) [1..2]
```
-1. Enter `1` to create a new Java Library project that is described in Groovy DSL. The output should be:
+1. Enter `1` to create a new Java Library project that is described in Groovy DSL, or `2` to create one that is described in Kotlin DSL. The output should be:
```plaintext
Select test framework:
@@ -286,7 +286,7 @@ To authenticate to the Package Registry, you need either a personal access token
In [your `GRADLE_USER_HOME` directory](https://docs.gradle.org/current/userguide/directory_layout.html#dir:gradle_user_home),
create a file `gradle.properties` with the following content:
-```groovy
+```properties
gitLabPrivateToken=REPLACE_WITH_YOUR_PERSONAL_ACCESS_TOKEN
```
@@ -310,6 +310,24 @@ repositories {
}
```
+Or add it to your `build.gradle.kts` file if you are using Kotlin DSL:
+
+```kotlin
+repositories {
+ maven {
+ url = uri("https://gitlab.example.com/api/v4/groups/<group>/-/packages/maven")
+ name = "GitLab"
+ credentials(HttpHeaderCredentials::class) {
+ name = "Private-Token"
+ value = findProperty("gitLabPrivateToken") as String?
+ }
+ authentication {
+ create("header", HttpHeaderAuthentication::class)
+ }
+ }
+}
+```
+
### Authenticate with a deploy token in Gradle
To authenticate with a deploy token, add a `repositories` section to your
@@ -332,6 +350,24 @@ repositories {
}
```
+Or add it to your `build.gradle.kts` file if you are using Kotlin DSL:
+
+```kotlin
+repositories {
+ maven {
+ url = uri("https://gitlab.example.com/api/v4/groups/<group>/-/packages/maven")
+ name = "GitLab"
+ credentials(HttpHeaderCredentials::class) {
+ name = "Deploy-Token"
+ value = "<deploy-token>"
+ }
+ authentication {
+ create("header", HttpHeaderAuthentication::class)
+ }
+ }
+}
+```
+
### Authenticate with a CI job token in Gradle
To authenticate with a CI job token, add a `repositories` section to your
@@ -354,6 +390,24 @@ repositories {
}
```
+Or add it to your `build.gradle.kts` file if you are using Kotlin DSL:
+
+```kotlin
+repositories {
+ maven {
+ url = uri("$CI_API_V4_URL/groups/<group>/-/packages/maven")
+ name = "GitLab"
+ credentials(HttpHeaderCredentials::class) {
+ name = "Job-Token"
+ value = System.getenv("CI_JOB_TOKEN")
+ }
+ authentication {
+ create("header", HttpHeaderAuthentication::class)
+ }
+ }
+}
+```
+
## Use the GitLab endpoint for Maven packages
To use the GitLab endpoint for Maven packages, choose an option:
@@ -397,7 +451,7 @@ in Maven should look like this:
</distributionManagement>
```
-The corresponding section in Gradle would be:
+The corresponding section in Gradle Groovy DSL would be:
```groovy
repositories {
@@ -408,6 +462,17 @@ repositories {
}
```
+In Kotlin DSL:
+
+```kotlin
+repositories {
+ maven {
+ url = uri("https://gitlab.example.com/api/v4/projects/PROJECT_ID/packages/maven")
+ name = "GitLab"
+ }
+}
+```
+
- The `id` is what you [defined in `settings.xml`](#authenticate-to-the-package-registry-with-maven).
- 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.
@@ -454,7 +519,7 @@ the `distributionManagement` section:
</distributionManagement>
```
-For Gradle, the corresponding `repositories` section would look like:
+For Gradle, the corresponding `repositories` section in Groovy DSL would look like:
```groovy
repositories {
@@ -465,6 +530,17 @@ repositories {
}
```
+In Kotlin DSL:
+
+```kotlin
+repositories {
+ maven {
+ url = uri("https://gitlab.example.com/api/v4/groups/GROUP_ID/-/packages/maven")
+ name = "GitLab"
+ }
+}
+```
+
- For the `id`, use what you [defined in `settings.xml`](#authenticate-to-the-package-registry-with-maven).
- For `GROUP_ID`, use your group ID, which you can view on your group's home page.
- For `PROJECT_ID`, use your project ID, which you can view on your project's home page.
@@ -513,7 +589,7 @@ You still need a project-specific URL in the `distributionManagement` section.
</distributionManagement>
```
-The corresponding repositories section in Gradle would look like:
+The corresponding repositories section in Gradle Groovy DSL would look like:
```groovy
repositories {
@@ -524,6 +600,17 @@ repositories {
}
```
+In Kotlin DSL:
+
+```kotlin
+repositories {
+ maven {
+ url = uri("https://gitlab.example.com/api/v4/packages/maven")
+ name = "GitLab"
+ }
+}
+```
+
- The `id` is what you [defined in `settings.xml`](#authenticate-to-the-package-registry-with-maven).
- 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.
@@ -566,6 +653,8 @@ To publish a package by using Gradle:
1. Add the Gradle plugin [`maven-publish`](https://docs.gradle.org/current/userguide/publishing_maven.html) to the plugins section:
+ In Groovy DSL:
+
```groovy
plugins {
id 'java'
@@ -573,8 +662,19 @@ To publish a package by using Gradle:
}
```
+ In Kotlin DSL:
+
+ ```kotlin
+ plugins {
+ java
+ `maven-publish`
+ }
+ ```
+
1. Add a `publishing` section:
+ In Groovy DSL:
+
```groovy
publishing {
publications {
@@ -597,6 +697,31 @@ To publish a package by using Gradle:
}
```
+ In Kotlin DSL:
+
+ ```kotlin
+ publishing {
+ publications {
+ create<MavenPublication>("library") {
+ from(components["java"])
+ }
+ }
+ repositories {
+ maven {
+ url = uri("https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/maven")
+ credentials(HttpHeaderCredentials::class) {
+ name = "Private-Token"
+ value =
+ findProperty("gitLabPrivateToken") as String? // the variable resides in $GRADLE_USER_HOME/gradle.properties
+ }
+ authentication {
+ create("header", HttpHeaderAuthentication::class)
+ }
+ }
+ }
+ }
+ ```
+
1. Replace `PROJECT_ID` with your project ID, which can be found on your project's home page.
1. Run the publish task:
@@ -703,6 +828,14 @@ dependencies {
}
```
+Or to `build.gradle.kts` if you are using Kotlin DSL:
+
+```kotlin
+dependencies {
+ implementation("com.mycompany.mydepartment:my-project:1.0-SNAPSHOT")
+}
+```
+
### Request forwarding to Maven Central
> [Introduced](<https://gitlab.com/gitlab-org/gitlab/-/issues/362657>) behind a [feature flag](../../feature_flags.md), disabled by default in GitLab 15.4