首頁  >  文章  >  Java  >  Java開源開發者指南:構建並部署到Maven Central

Java開源開發者指南:構建並部署到Maven Central

王林
王林原創
2024-07-29 16:45:10961瀏覽

目錄

  • 建立GitHub帳戶(如果還沒有)
  • 申請Maven Central Repository帳戶
  • Java Doc
  • 發佈設定(Deployment Config)
  • GPG
  • 開發者資訊(Developer Information)
  • 來源程式碼管理(SCM)
  • 版權宣告(Licenses)
  • 範例POM檔

Sign maven central repository

註冊Namespace

請務必以github進行登錄,這樣就可以有免費的namespace可以用

原文
If you do not see this pop-up AND you signed up with GitHub, then Sonatype was able to grant you permissions to the namespace associated with your GitHub identity automatically. As part of your GHubiated with your GitHub identity automatically. As part of your GHubHub subscription GitHubwion sutomatically. As part that reflects your username and allows you to publish GitHub Pages under that domain. Because of this, Sonatype can, in most cases, automatically verify and provision publishing access to a namespace that looks likematically verify and provision publishing access to a namespace that looks like like like like like like ..

Deployment config

找到namespace

Java開源開發者指南:構建並部署到Maven Central
Java開源開發者指南:構建並部署到Maven Central

務必確保資料一致

<groupId>io.github.internetms52</groupId>
<artifactId>object-pool</artifactId>
<version>0.1.3</version>
<name>object-pool</name>
<packaging>jar</packaging>
<url>https://github.com/internetms52/object-pool-maven-lib</url>
<description>This is a library that implements an Object Pool, and it supports nested object creation as well as constructor specification.</description>
Generate User Token

View Account > Generate User Token

完成後就會取得settings.xml所需的資訊

Java開源開發者指南:構建並部署到Maven Central

指定server(settings.xml)

<settings>
    <servers>
        <server>
            <id>central</id>
            <username>XXXXXX</username>
            <password>YYYYYY</password>
        </server>
    </servers>
</settings>
指定maven central repository server設定(pom.xml)

<plugin>
    <groupId>org.sonatype.central</groupId>
    <artifactId>central-publishing-maven-plugin</artifactId>
    <version>0.5.0</version>
    <extensions>true</extensions>
    <configuration>
        <publishingServerId>central</publishingServerId>
    </configuration>
</plugin>
Java doc

使用Maven Plugin產生Java Doc

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>3.2.0</version>
    <executions>
        <execution>
            <id>attach-javadocs</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>
GPG

產生GPG Key Pair

sudo apt-get install gnupg
gpg --full-generate-key
gpg --list-keys
GPG簽名plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-gpg-plugin</artifactId>
    <version>3.0.1</version>
    <executions>
        <execution>
            <id>sign-artifacts</id>
            <phase>verify</phase>
            <goals>
                <goal>sign</goal>
            </goals>
            <configuration>
                <gpgArguments>
                    <arg>--pinentry-mode</arg>
                    <arg>loopback</arg>
                </gpgArguments>
            </configuration>
        </execution>
    </executions>
</plugin>
上傳GPG公鑰

GPG的公鑰server有兩個比較有名的

    pgp.mit.edu
  • keyserver.ubuntu.com
gpg --keyserver hkp://pgp.mit.edu --send-keys F1BD06AB06C36BD5EB53B6E8710DEC40549547D2
gpg: sending key 710DEC40549547D2 to hkp://pgp.mit.edu

gpg --keyserver hkp://keyserver.ubuntu.com --send-keys F1BD06AB06C36BD5EB53B6E8710DEC40549547D2
gpg: sending key 710DEC40549547D2 to hkp://keyserver.ubuntu.com
Developer info

<developers>
    <developer>
        <name>LU.YU HSIN</name>
        <email>yourmail@mail.com</email>
        <organization>internetms52</organization>
        <organizationUrl>https://github.com/internetms52/object-pool-maven-lib</organizationUrl>
    </developer>
</developers>
SCM

<scm>
    <connection>scm:git:git@github.com:internetms52/object-pool-maven-lib.git</connection>
    <developerConnection>scm:git:git@github.com:internetms52/object-pool-maven-lib.git</developerConnection>
    <url>https://github.com/internetms52/object-pool-maven-lib</url>
</scm>
Licenses

<licenses>
    <license>
        <name>Apache License, Version 2.0</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        <distribution>repo</distribution>
    </license>
</licenses>
範例 POM

object-pool-maven-lib

以上是Java開源開發者指南:構建並部署到Maven Central的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn