2022-03-30 11:42:47 +03:00
---
date: "2021-07-20T00:00:00+00:00"
2023-05-24 09:21:39 +03:00
title: "Maven Package Registry"
Refactor docs (#23752)
This was intended to be a small followup for
https://github.com/go-gitea/gitea/pull/23712, but...here we are.
1. Our docs currently use `slug` as the entire URL, which makes
refactoring tricky (see https://github.com/go-gitea/gitea/pull/23712).
Instead, this PR attempts to make future refactoring easier by using
slugs as an extension of the section. (Hugo terminology)
- What the above boils down to is this PR attempts to use directory
organization as URL management. e.g. `usage/comparison.en-us.md` ->
`en-us/usage/comparison/`, `usage/packages/overview.en-us.md` ->
`en-us/usage/packages/overview/`
- Technically we could even remove `slug`, as Hugo defaults to using
filename, however at least with this PR it means `slug` only needs to be
the name for the **current file** rather than an entire URL
2. This PR adds appropriate aliases (redirects) for pages, so anything
on the internet that links to our docs should hopefully not break.
3. A minor nit I've had for a while, renaming `seek-help` to `support`.
It's a minor thing, but `seek-help` has a strange connotation to it.
4. The commits are split such that you can review the first which is the
"actual" change, and the second is added redirects so that the first
doesn't break links elsewhere.
---------
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2023-04-28 06:33:41 +03:00
slug: "maven"
2023-07-26 07:53:13 +03:00
sidebar_position: 60
2022-03-30 11:42:47 +03:00
draft: false
toc: false
menu:
sidebar:
parent: "packages"
name: "Maven"
2023-07-26 07:53:13 +03:00
sidebar_position: 60
2022-03-30 11:42:47 +03:00
identifier: "maven"
---
2023-05-24 09:21:39 +03:00
# Maven Package Registry
2022-03-30 11:42:47 +03:00
Publish [Maven ](https://maven.apache.org ) packages for your user or organization.
## Requirements
To work with the Maven package registry, you can use [Maven ](https://maven.apache.org/install.html ) or [Gradle ](https://gradle.org/install/ ).
2023-03-10 06:14:59 +03:00
The following examples use `Maven` and `Gradle Groovy` .
2022-03-30 11:42:47 +03:00
## Configuring the package registry
To register the package registry you first need to add your access token to the [`settings.xml` ](https://maven.apache.org/settings.html ) file:
```xml
< settings >
< servers >
< server >
< id > gitea< / id >
< configuration >
< httpHeaders >
< property >
< name > Authorization< / name >
< value > token {access_token}< / value >
< / property >
< / httpHeaders >
< / configuration >
< / server >
< / servers >
< / settings >
```
Afterwards add the following sections to your project `pom.xml` file:
```xml
< repositories >
< repository >
< id > gitea< / id >
< url > https://gitea.example.com/api/packages/{owner}/maven< / url >
< / repository >
< / repositories >
< distributionManagement >
< repository >
< id > gitea< / id >
< url > https://gitea.example.com/api/packages/{owner}/maven< / url >
< / repository >
< snapshotRepository >
< id > gitea< / id >
< url > https://gitea.example.com/api/packages/{owner}/maven< / url >
< / snapshotRepository >
< / distributionManagement >
```
| Parameter | Description |
| -------------- | ----------- |
2023-07-26 07:53:13 +03:00
| `access_token` | Your [personal access token ](development/api-usage.md#authentication ). |
2022-03-30 11:42:47 +03:00
| `owner` | The owner of the package. |
2023-03-10 06:14:59 +03:00
### Gradle variant
When you plan to add some packages from Gitea instance in your project, you should add it in repositories section:
```groovy
repositories {
// other repositories
maven { url "https://gitea.example.com/api/packages/{owner}/maven" }
}
```
In Groovy gradle you may include next script in your publishing part:
```groovy
publishing {
// other settings of publication
repositories {
maven {
name = "Gitea"
url = uri("https://gitea.example.com/api/packages/{owner}/maven")
credentials(HttpHeaderCredentials) {
name = "Authorization"
value = "token {access_token}"
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
```
2022-03-30 11:42:47 +03:00
## Publish a package
To publish a package simply run:
```shell
mvn deploy
```
2023-03-10 06:14:59 +03:00
Or call `gradle` with task `publishAllPublicationsToGiteaRepository` in case you are using gradle:
```groovy
./gradlew publishAllPublicationsToGiteaRepository
```
2022-08-07 16:58:03 +03:00
If you want to publish a prebuild package to the registry, you can use [`mvn deploy:deploy-file` ](https://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html ):
```shell
mvn deploy:deploy-file -Durl=https://gitea.example.com/api/packages/{owner}/maven -DrepositoryId=gitea -Dfile=/path/to/package.jar
```
| Parameter | Description |
| -------------- | ----------- |
| `owner` | The owner of the package. |
2022-03-30 11:42:47 +03:00
You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
## Install a package
To install a Maven package from the package registry, add a new dependency to your project `pom.xml` file:
```xml
< dependency >
< groupId > com.test.package< / groupId >
< artifactId > test_project< / artifactId >
< version > 1.0.0< / version >
< / dependency >
```
2023-03-10 06:14:59 +03:00
And analog in gradle groovy:
```groovy
implementation "com.test.package:test_project:1.0.0"
```
2022-03-30 11:42:47 +03:00
Afterwards run:
```shell
mvn install
```
## Supported commands
```
mvn install
mvn deploy
mvn dependency:get:
2022-07-28 04:22:47 +03:00
```