1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-10-31 08:37:35 -04:00
gitea/docs/content/doc/packages/maven.en-us.md
Lunny Xiao e8433b7fe6
Restructure documentation. Now the documentation has installation, administration, usage, development, contributing the 5 main parts (#23629)
- **Installation**: includes how to install Gitea and related other
tools, also includes upgrade Gitea
- **Administration**: includes how to configure Gitea, customize Gitea
and manage Gitea instance out of Gitea admin UI
- **Usage**: includes how to use Gitea's functionalities. A sub
documentation is about packages, in future we could also include CI/CD
and others.
- **Development**: includes how to integrate with Gitea's API, how to
develop new features within Gitea
- **Contributing**: includes how to contribute code to Gitea
repositories.

After this is merged, I think we can have a sub-documentation of `Usage`
part named `Actions` to describe how to use Gitea actions

---------

Co-authored-by: John Olheiser <john.olheiser@gmail.com>
2023-03-23 23:18:24 +08:00

3.9 KiB

date title slug draft toc menu
2021-07-20T00:00:00+00:00 Maven Packages Repository usage/packages/maven false false
sidebar
parent name weight identifier
packages Maven 60 maven

Maven Packages Repository

Publish Maven packages for your user or organization.

Table of Contents

{{< toc >}}

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

<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
access_token Your [personal access token]({{< relref "doc/development/api-usage.en-us.md#authentication" >}}).
owner The owner of the package.

Gradle variant

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

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:

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

Publish a package

To publish a package simply run:

mvn deploy

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

./gradlew publishAllPublicationsToGiteaRepository

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

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.

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: