One, foreword

We recently developed a component called MultithreadPool-spring-boot-starter in the process of learning Spring Boot. With this component, we can dynamically initialize multiple thread pools based on configuration files. Since you have this output, you must want to upload it to the Maven central repository for more people to use, hence the project release experience.

The whole process can be described as twists and turns, because usually busy work can only spend an hour in the evening, so after nearly a week, finally successfully released.

The following I was uploaded to record the process, I hope to help more friends.

 

Two, environmental preparation

1> MAC OSX 10.14.6: This document is based on the MAC environment

2> Apache Maven 3.2.3: This article focuses on building and releasing examples using Maven

 

Step description

1. Work order creation

1> Visit Sonatype and register with issues.sonatype.org. Remember the account password for our subsequent releases and related operations

2> Create an issue as shown in the figure, and select Community Support-Open Source Project Repository Hosting for the Project

 

3> Refer to the picture below to fill in the outline, Group Id, project address, code management address, and click to confirm submission. A lot of people online say it takes hours or the next day to get a response. I waited 10 minutes to get a response. At this point, the person tells you two things:

  • 【 Reminder 】 Make sure that the domain name corresponding to the group ID is yours
  • [Verification] For example, my project address is on Github, and he will require me to create a project with the same name as the issue on Github to ensure that I have the management rights of the project.

After confirming and creating a project with the same name as the issue, remember to reply to the issue at Sonatype – Issue and Github repositories

4> After passing the above confirmation and verification, Sonatype will reply you with the Snapshot address and release address used for maven press release, and remind you that you need to reply to this issue after the first release. Please refer to issue for details

 

2. GPG environment installation

The main role of GPG is to generate key pairs that will be used for verification of subsequent component releases.

1> Download from www.gnupg.org/download/

2> Download and install as shown in the red box

3> After the installation is complete, run the following command to generate the key pair, and enter the account, email address, and password as prompted (PS: the password will be used in the press conference later, please be sure to remember).

gpg2 --gen-key Copy the code

4> Run the command to view the key. The console will output something similar to the following

$ gpg2 --list-keys Copy the code
.Copy the code

Pub rSA2048 2019-04-12 [SC] [valid to: Uid [2021-04-11] 9 a1640f7a2551131612d51b12d83594b7b29d86a absolute] xiaoxuetu < [email protected] > sub rsa2048, 2019-04-12 [E] [Valid until: 2021-04-11]

5> Run the following command to publish the public key to the server

$ gpg --keyserver hkp://subkeys.pgp.net --send-keys 9A1640F7A2551131612D51B12D83594B7B29D86A ... GPG: sending the key 2D83594B7B29D86A to hkp://subkeys.pgp.net GPG: sending the key to the public key Server failed: Server indicated a failure GPG: Server indicated a failure to send to the public key ServerCopy the code

6> If the console outputs an error similar to the one above, adjust the key in the command to 2D83594B7B29D86A

$ gpg --keyserver hkp://subkeys.pgp.net --send-keys 2D83594B7B29D86A

Copy the code

  gpg: sending key E2A36372591567B3 to hkp://pool.sks-keyservers.net

 Copy the code

 

3. Maven global configuration

In general, maven global configuration exists inMake a copy of {MAVEN_HOME}/conf/setting. XML to ${HOME}/.m2 and make the following changes

1> Add server authentication information

    <server>
      <id>sonatype_releases</id>
      <username>your user name</username>
      <password>your password</password>
    </server>
    <server>
      <id>sonatype_snapshots</id>
      <username>your user name</username>
      <password>your password</password>
    </server>Copy the code

 

2> Configure the GPG authentication command

<settings> <profiles> <profile> <id>gpg</id> <properties> <! -- GpG2 is installed on my computer, there is no GPG command, so I need to specify gpg2. Gpg2 </ GPG. Executable > < GPG. Passphrase > Your password</ GPG. Passphrase > </properties> </profile> </profiles> <activeProfiles> <activeProfile>gpg</activeProfile> </activeProfiles> </settings>Copy the code

 

4. Project Maven configuration

1> In the project’s POM.xml, configure the appropriate open source protocol, warehouse information, developer information, and publishing configuration

<! --> <licenses> <name>The Apache Software license, Version 2.0 < / name > < url > http://www.apache.org/licenses/LICENSE-2.0.txt < / url > < distribution > '< / distribution > </license> </licenses> <! - warehouse information - > < SCM > < connection > scm:git:[email protected]: xiaoxuetu/multithreadpool - spring - the boot - starter. Git < / connection > <developerConnection>scm:git:[email protected]:xiaoxuetu/multithreadpool-spring-boot-starter.git </developerConnection> <url>http://github.com/xiaoxuetu/multithreadpool-spring-boot-starter/tree/master</url> </scm> <! <name>xiaoxuetu</name> <email>[email protected]</email> <organization>https://github.com/xiaoxuetu</organization> <timezone>+8</timezone> </developer> </developers> <! <distributionManagement> <repository> <! > < ID > Sonatype_releases </ ID > <name>Nexus Release Repository</name> <! After creating the issue successfully, Response to the release of release address - > < url > https://oss.sonatype.org/service/local/staging/deploy/maven2 < / url > < / repository > <snapshotRepository> <! Snapshots: <id>sonatype_snapshots</id> <name>Nexus snapshot Repository</name> <! After creating the issue successfully, The snapshot of response to address - > < url > https://oss.sonatype.org/content/repositories/snapshots < / url > < / snapshotRepository > </distributionManagement>Copy the code

 

2> Since publishing to Maven’s central repository requires us to simultaneously publish to Javadoc, Source, and ASC (using GPG generation to verification) at the same time as uploading jars to Maven, we need to add the following build plug-ins to Maven

<build> <plugins> <plugin> <groupId>org.sonatype.plugins</groupId> <artifactId>nexus-staging-maven-plugin</artifactId> The < version > 1.6.7 < / version > < extensions > true < / extensions > < configuration > <! > <serverId> Sonatype_releases </serverId> <nexusUrl>https://oss.sonatype.org/</nexusUrl> <! If you want to automatically execute close and release after publishing, <autoReleaseAfterClose>false</autoReleaseAfterClose> </configuration> </plugin> <! Plugin > <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <executions> <id>attach-sources</id> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <! Plugins </groupId> <artifactId> Plugins </artifactId> maven-gpg-plugin</artifactId> The < version > 1.5 < / version > < executions > < execution > <! GPG </ ID > <phase>verify</phase> <goals> <goal>sign</goal> </execution> </executions>  </plugin> </plugins> </build>Copy the code

  

5. Release operation

1> Execute the following command to publish (if the value of autoReleaseAfterClose in POM.xml is true, the script will automatically complete the close and release operations on the platform and you will have published successfully, otherwise we will continue to step 2)

 mvn clean javadoc:jar deploy -P releaseCopy the code

 

2> Log in to https://oss.sonatype.org and select Staging Repositories

 

3> Search for and select components to be published as shown in the following figure, and perform Close and Release operations in sequence

 

4> If Release is successful and you are the first to Release the component, you need to reply “I have successfully published this component” to your create to Issue, after about 2 hours, the component will be synchronized to the corresponding Maven repository

5> If Close or Release is not successful, you can check the reason and Google for positioning or reply to consult as shown in the picture below

 

Iv. Reference documents

1> Release artifacts to Maven’s central repository: juejin.cn/post/684490…

2 > Working with PGP Signatures: central.sonatype.org/pages/worki…

3 > Deploying to OSSRH with Apache Maven: central.sonatype.org/pages/apach…