code.gitea.io/gitea@v1.22.3/docs/content/usage/packages/maven.en-us.md (about)

     1  ---
     2  date: "2021-07-20T00:00:00+00:00"
     3  title: "Maven Package Registry"
     4  slug: "maven"
     5  sidebar_position: 60
     6  draft: false
     7  toc: false
     8  menu:
     9    sidebar:
    10      parent: "packages"
    11      name: "Maven"
    12      sidebar_position: 60
    13      identifier: "maven"
    14  ---
    15  
    16  # Maven Package Registry
    17  
    18  Publish [Maven](https://maven.apache.org) packages for your user or organization.
    19  
    20  ## Requirements
    21  
    22  To work with the Maven package registry, you can use [Maven](https://maven.apache.org/install.html) or [Gradle](https://gradle.org/install/).
    23  The following examples use `Maven` and `Gradle Groovy`.
    24  
    25  ## Configuring the package registry
    26  
    27  To register the package registry you first need to add your access token to the [`settings.xml`](https://maven.apache.org/settings.html) file:
    28  
    29  ```xml
    30  <settings>
    31    <servers>
    32      <server>
    33        <id>gitea</id>
    34        <configuration>
    35          <httpHeaders>
    36            <property>
    37              <name>Authorization</name>
    38              <value>token {access_token}</value>
    39            </property>
    40          </httpHeaders>
    41        </configuration>
    42      </server>
    43    </servers>
    44  </settings>
    45  ```
    46  
    47  Afterwards add the following sections to your project `pom.xml` file:
    48  
    49  ```xml
    50  <repositories>
    51    <repository>
    52      <id>gitea</id>
    53      <url>https://gitea.example.com/api/packages/{owner}/maven</url>
    54    </repository>
    55  </repositories>
    56  <distributionManagement>
    57    <repository>
    58      <id>gitea</id>
    59      <url>https://gitea.example.com/api/packages/{owner}/maven</url>
    60    </repository>
    61    <snapshotRepository>
    62      <id>gitea</id>
    63      <url>https://gitea.example.com/api/packages/{owner}/maven</url>
    64    </snapshotRepository>
    65  </distributionManagement>
    66  ```
    67  
    68  | Parameter      | Description |
    69  | -------------- | ----------- |
    70  | `access_token` | Your [personal access token](development/api-usage.md#authentication). |
    71  | `owner`        | The owner of the package. |
    72  
    73  ### Gradle variant
    74  
    75  When you plan to add some packages from Gitea instance in your project, you should add it in repositories section:
    76  
    77  ```groovy
    78  repositories {
    79      // other repositories
    80      maven { url "https://gitea.example.com/api/packages/{owner}/maven" }
    81  }
    82  ```
    83  
    84  In Groovy gradle you may include next script in your publishing part:
    85  
    86  ```groovy
    87  publishing {
    88      // other settings of publication
    89      repositories {
    90          maven {
    91              name = "Gitea"
    92              url = uri("https://gitea.example.com/api/packages/{owner}/maven")
    93  
    94              credentials(HttpHeaderCredentials) {
    95                  name = "Authorization"
    96                  value = "token {access_token}"
    97              }
    98  
    99              authentication {
   100                  header(HttpHeaderAuthentication)
   101              }
   102          }
   103      }
   104  }
   105  ```
   106  
   107  ## Publish a package
   108  
   109  To publish a package simply run:
   110  
   111  ```shell
   112  mvn deploy
   113  ```
   114  
   115  Or call `gradle` with task `publishAllPublicationsToGiteaRepository` in case you are using gradle:
   116  
   117  ```groovy
   118  ./gradlew publishAllPublicationsToGiteaRepository
   119  ```
   120  
   121  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):
   122  
   123  ```shell
   124  mvn deploy:deploy-file -Durl=https://gitea.example.com/api/packages/{owner}/maven -DrepositoryId=gitea -Dfile=/path/to/package.jar
   125  ```
   126  
   127  | Parameter      | Description |
   128  | -------------- | ----------- |
   129  | `owner`        | The owner of the package. |
   130  
   131  You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
   132  
   133  ## Install a package
   134  
   135  To install a Maven package from the package registry, add a new dependency to your project `pom.xml` file:
   136  
   137  ```xml
   138  <dependency>
   139    <groupId>com.test.package</groupId>
   140    <artifactId>test_project</artifactId>
   141    <version>1.0.0</version>
   142  </dependency>
   143  ```
   144  
   145  And analog in gradle groovy:
   146  
   147  ```groovy
   148  implementation "com.test.package:test_project:1.0.0"
   149  ```
   150  
   151  Afterwards run:
   152  
   153  ```shell
   154  mvn install
   155  ```
   156  
   157  ## Supported commands
   158  
   159  ```
   160  mvn install
   161  mvn deploy
   162  mvn dependency:get:
   163  ```