2023-02-26 18:08:07 -05:00
---
2023-06-05 12:24:04 -04:00
title: 'Maven Package Registry'
2023-03-03 01:44:11 -05:00
license: 'Apache-2.0'
2023-07-18 13:25:15 -04:00
origin_url: 'https://github.com/go-gitea/gitea/blob/faa28b5a44912f1c63afddab9396bae9e6fe061c/docs/content/doc/usage/packages/maven.en-us.md'
2023-02-26 18:08:07 -05: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 07:09:47 -05:00
The following examples use `Maven` and `Gradle Groovy` .
2023-02-26 18:08:07 -05: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 > forgejo< / 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 > forgejo< / id >
< url > https://forgejo.example.com/api/packages/{owner}/maven< / url >
< / repository >
< / repositories >
< distributionManagement >
< repository >
< id > forgejo< / id >
< url > https://forgejo.example.com/api/packages/{owner}/maven< / url >
< / repository >
< snapshotRepository >
< id > forgejo< / id >
< url > https://forgejo.example.com/api/packages/{owner}/maven< / url >
< / snapshotRepository >
< / distributionManagement >
```
2023-08-19 11:14:45 -04:00
| Parameter | Description |
| -------------- | -------------------------------------------------------------- |
| `access_token` | Your [personal access token ](../../api-usage/#authentication ). |
| `owner` | The owner of the package. |
2023-03-10 07:09:47 -05:00
### Gradle variant
When you plan to add some packages from Forgejo instance in your project, you should add it in repositories section:
```groovy
repositories {
// other repositories
maven { url "https://forgejo.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 = "Forgejo"
url = uri("https://forgejo.example.com/api/packages/{owner}/maven")
credentials(HttpHeaderCredentials) {
name = "Authorization"
value = "token {access_token}"
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
```
2023-02-26 18:08:07 -05:00
## Publish a package
To publish a package simply run:
```shell
mvn deploy
```
2023-03-10 07:09:47 -05:00
Or call `gradle` with task `publishAllPublicationsToForgejoRepository` in case you are using gradle:
```groovy
./gradlew publishAllPublicationsToForgejoRepository
```
2023-02-26 18:08:07 -05: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://forgejo.example.com/api/packages/{owner}/maven -DrepositoryId=forgejo -Dfile=/path/to/package.jar
```
2023-03-31 16:57:57 -04:00
| Parameter | Description |
| --------- | ------------------------- |
| `owner` | The owner of the package. |
2023-02-26 18:08:07 -05: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 07:09:47 -05:00
And analog in gradle groovy:
```groovy
implementation "com.test.package:test_project:1.0.0"
```
2023-02-26 18:08:07 -05:00
Afterwards run:
```shell
mvn install
```
## Supported commands
```
mvn install
mvn deploy
mvn dependency:get:
```