0
0
Fork 0
mirror of https://codeberg.org/forgejo/docs.git synced 2024-12-01 19:17:12 -05:00
forgejo-docs/docs/user/packages/maven.md
Earl Warren ae97171f57 sync with the latest changes from Gitea
git log --patch faa28b5a44912f1c63afddab9396bae9e6fe061c..8d9e2d07f3f84a86265fdbe0ab7fcf63cc34ddbd . ':(glob)docs/**/*.en-us.md'

(cherry picked from commit b77359bfb1)
2023-09-22 17:36:27 +00:00

3.9 KiB

title license origin_url
Maven Package Registry Apache-2.0 8d9e2d07f3/docs/content/usage/packages/maven.en-us.md

Publish Maven packages for your user or organization.

Requirements

To work with the Maven package registry, you can use Maven or Gradle. The following examples use Maven and Gradle Groovy.

Configuring the package registry

To register the package registry you first need to add your access token to the settings.xml file:

<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:

<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>
Parameter Description
access_token Your personal access token.
owner The owner of the package.

Gradle variant

When you plan to add some packages from Forgejo instance in your project, you should add it in repositories section:

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:

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)
            }
        }
    }
}

Publish a package

To publish a package simply run:

mvn deploy

Or call gradle with task publishAllPublicationsToForgejoRepository in case you are using gradle:

./gradlew publishAllPublicationsToForgejoRepository

If you want to publish a prebuild package to the registry, you can use mvn deploy:deploy-file:

mvn deploy:deploy-file -Durl=https://forgejo.example.com/api/packages/{owner}/maven -DrepositoryId=forgejo -Dfile=/path/to/package.jar
Parameter Description
owner The owner of the package.

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:

<dependency>
  <groupId>com.test.package</groupId>
  <artifactId>test_project</artifactId>
  <version>1.0.0</version>
</dependency>

And analog in gradle groovy:

implementation "com.test.package:test_project:1.0.0"

Afterwards run:

mvn install

Supported commands

mvn install
mvn deploy
mvn dependency:get: