Home  >  Article  >  Java  >  Java Open Source Developer's Guide: Build and Deploy to Maven Central

Java Open Source Developer's Guide: Build and Deploy to Maven Central

王林
王林Original
2024-07-29 16:45:101022browse

Table of contents

  • Create a GitHub account if you don’t have one yet
  • Apply for a Maven Central Repository account
  • Java Doc
  • Deployment Config
  • GPG
  • Developer Information
  • Source Code Management (SCM)
  • Copyright Notice (Licenses)
  • Example POM file

Sign maven central repository

Register Namespace

Please be sure to log in with github, so that you can use the free namespace

Original text
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 GitHub subscription, GitHub provides you with a github.io domain 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 like io.github..

Deployment config

find namespace

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

Make sure the information is consistent

<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
After completion, the information required by settings.xml will be obtained
Java開源開發者指南:構建並部署到Maven Central

Specify server(settings.xml)

<settings>
    <servers>
        <server>
            <id>central</id>
            <username>XXXXXX</username>
            <password>YYYYYY</password>
        </server>
    </servers>
</settings>

Specify maven central repository server settings (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>

Javadoc

Generate Java Doc using Maven Plugin

<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

Generate GPG Key Pair

sudo apt-get install gnupg
gpg --full-generate-key
gpg --list-keys

GPG signature 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>

Upload GPG public key

There are two famous GPG public key servers

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

Example POM

object-pool-maven-lib

The above is the detailed content of Java Open Source Developer's Guide: Build and Deploy to Maven Central. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:AI in CybersecurityNext article:AI in Cybersecurity