I heard that wechat search “Java fish” will change strong oh!

This article is in Java Server, which contains my complete series of Java articles, can be read for study or interview

(1) Overview

There are many tutorials for uploading JAR packages to the central repository on the Internet, but AFTER doing a lot of searching, I found that the method of uploading JAR packages to the central repository is not applicable at present. Therefore, I decided to write down the method of uploading JAR packages to the central repository on August 18, 2021.

(2) Register JIRA

This document uplows jar packages to the Maven central repository via Sonatype, which manages the OSSRH repository via JIRA, so register a JIRA account first

Issues.sonatype.org/secure/Sign…

(3) Issuing applications

After jIRA is created, we need to submit an application to upload the JAR package:

Issues.sonatype.org/secure/Crea…

GroupId can fill in its own domain name. If not, you can fill in IO. Github.[your Github account name]

Once created, someone will process your request and comment on it in a comment. If it passes, the status of the problem will change to resolved

(iv) Release projects

When the request is approved, the handler sends a successful processing message with the tutorial address for the published project:

Central.sonatype.org/publish/pub…

Although this tutorial is posted in great detail, it is all in English and a bit messy, so I will post it in this article

4.1 Installing and Configuring GPG

All files published to the Maven repository are signed with GPG to ensure integrity, so we need to create the GPG and download the GPG first

https//www.gnupg.org/download/

After the installation is complete, type GPG –version on the command line. If the specific version number pops up, the installation is successful.

Run the GPG –gen-key command to generate the key, during which the user name, email address, and password are entered and the password is remembered.

GPG –list-keys: GPG –list-keys: public key

GPG --keyserver keyserver.ubuntu.com --send-keys Your keyCopy the code

After the message is sent, a message is displayed indicating that the message is sent successfully

4.2 Configuring Maven setting.xml

Setting. XML is maven’s configuration file. You can find the path of setting

Deploying OSSRH authentication information:

<settings>
  	<servers>
    		<server>
      			<id>ossrh</id>
      			<username>your-jira-id</username>
      			<password>your-jira-pwd</password>
    		</server>
  	</servers>
</settings>
Copy the code

At this point, the setting.xml configuration is complete

4.3 Configuring poM Files

Next configure the project’s POM file:

First fill in the information related to the project, such as groupId, developers and so on. Everyone is different in this area, so I will not explain too much here. Pay attention! GroupId must be the same as the one you filled in when submitting JIRA, otherwise it will not be uploaded. The following is for reference only:

<groupId>io.github.oliverliy</groupId>
<artifactId>fast-sso</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>fast-sso</name>
<url>https://github.com/OliverLiy/fast-sso</url>
<description>A fast access SSO project</description>
<licenses>
    <license>
        <name>The Apache License, Version 2.0</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        <distribution>repo</distribution>
        <comments>A business-friendly OSS license</comments>
    </license>
</licenses>
<scm>
    <url>https://github.com/OliverLiy/fast-sso</url>
    <connection>https://github.com/OliverLiy/fast-sso.git</connection>
</scm>
<modules>
    <module>fast-sso-client</module>
    <module>fast-sso-server</module>
    <module>fast-sso-example</module>
</modules>
<developers>
    <developer>
        <name>javayz</name>
        <id>javayz</id>
        <email>[email protected]</email>
        <roles>
            <role>Developer</role>
        </roles>
        <timezone>+ 8</timezone>
    </developer>
</developers>

<properties>
    <springboot.version>2.2.0. RELEASE</springboot.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>
Copy the code

Configure distributionManagement. Since February 2021, all new projects are configured on s01.oss.sonatype.org/, so the following configuration is in a…

<distributionManagement>
  <snapshotRepository>
    <id>ossrh</id>
    <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
  </snapshotRepository>
  <repository>
    <id>ossrh</id>
    <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
  </repository>
</distributionManagement>
Copy the code

Then configure the packaged plug-in, Javadoc and source Maven plug-in, Maven GPG plug-in

<build>
        <plugins>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.7</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <configuration>
                    <! Mysql > select * from jdk1.8;
                    <additionalJOptions>
                        <additionalJOption>-Xdoclint:none</additionalJOption>
                    </additionalJOptions>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
</build>
Copy the code

Finally, a complete copy of POM.xml is provided


      
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>io.github.oliverliy</groupId>
    <artifactId>fast-sso</artifactId>
    <version>0.0.1</version>
    <packaging>pom</packaging>
    <name>fast-sso</name>
    <url>https://github.com/OliverLiy/fast-sso</url>
    <description>A fast access SSO project</description>
    <licenses>
        <license>
            <name>The Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
            <comments>A business-friendly OSS license</comments>
        </license>
    </licenses>
    <scm>
        <url>https://github.com/OliverLiy/fast-sso</url>
        <connection>https://github.com/OliverLiy/fast-sso.git</connection>
    </scm>
    <modules>
        <module>fast-sso-client</module>
        <module>fast-sso-server</module>
        <module>fast-sso-example</module>
    </modules>
    <developers>
        <developer>
            <name>javayz</name>
            <id>javayz</id>
            <email>[email protected]</email>
            <roles>
                <role>Developer</role>
            </roles>
            <timezone>+ 8</timezone>
        </developer>
    </developers>

    <properties>
        <springboot.version>2.2.0. RELEASE</springboot.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <profiles>
        <profile>
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <distributionManagement>
                <snapshotRepository>
                    <id>ossrh</id>
                    <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
                </snapshotRepository>
                <repository>
                    <id>ossrh</id>
                    <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                </repository>
            </distributionManagement>
            <build>
                    <plugins>
                        <plugin>
                            <groupId>org.sonatype.plugins</groupId>
                            <artifactId>nexus-staging-maven-plugin</artifactId>
                            <version>1.6.7</version>
                            <extensions>true</extensions>
                            <configuration>
                                <serverId>ossrh</serverId>
                                <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                                <autoReleaseAfterClose>true</autoReleaseAfterClose>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-source-plugin</artifactId>
                            <version>2.2.1</version>
                            <executions>
                                <execution>
                                    <id>attach-sources</id>
                                    <goals>
                                        <goal>jar-no-fork</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-javadoc-plugin</artifactId>
                            <version>2.9.1</version>
                            <configuration>
                                <! Mysql > select * from jdk1.8;
                                <additionalJOptions>
                                    <additionalJOption>-Xdoclint:none</additionalJOption>
                                </additionalJOptions>
                            </configuration>
                            <executions>
                                <execution>
                                    <id>attach-javadocs</id>
                                    <goals>
                                        <goal>jar</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-gpg-plugin</artifactId>
                            <version>1.5</version>
                            <executions>
                                <execution>
                                    <id>sign-artifacts</id>
                                    <phase>verify</phase>
                                    <goals>
                                        <goal>sign</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
            </build>
        </profile>
    </profiles>
</project>
Copy the code

4.4 Uploading a Package

The last step is a simple one, execute the deploy command in the current directory

mvn clean deploy
Copy the code

Wait for a moment, the message “Build Success” indicates that the package is successfully packaged

(5) Release

After completing the above, log in nexus: s01.oss.sonatype.org/#stagingRep…

If there is a problem, click the Activity below to check the specific problem. Most of the problems affecting release are missing something during packaging, and you can fix them according to the problem.

After the detection is completed, the release on the top will become clickable. After clicking release, you will receive an email

The email means it takes about 30 minutes to sync to the Maven repository and about 4 hours to search at search.maven.org. I can now see my JAR packages in the central repository. Your JAR package can be used by others.

(6) Summary

Why mess with this thing? Because I am currently working on an open source project on unified authentication, I need to upload the JAR package to the central repository. The purpose of this open source project is to enable projects to quickly access the unified authentication system with some simple configuration, so I named this project fast-SSO, and will release an initial version later. I’m fish boy. See you next time!