The java project deploys jar s to the maven central repository

Release process overview:
1. Apply for sonatype account creation task
2. Install the gpg key pair and upload the private / key to the central warehouse server
3. Configuration item, maven/ pom configuration
4. Project inspection / release

1, Apply for sonatype account and create application release task

1.1 registered account

Official website: Add link description
Registered address: Add link description

1.2. Create task

Enter the home page and click new

Create task

  • group id, make sure that the domain name corresponding to the group id is yours. It's best to use com.github.wslxm directly according to its prompt. If you have your own official website, you can also use your website directly (you will be asked to verify later)
  • Project address
  • Code management address
  • Code management address

1.3 audit

After filling in, click confirm to submit to ensure that the task is open and waiting for review. The review will send an email notification,
If it does not meet their requirements, it will be set to Unresolved. You can repeatedly modify the relevant configuration information and submit it again for them to handle.

1.4 calibration

For example, my project address is on github. It will let you create a project required by github and submit it here

1.5. Approved / verified

After the approval / verification is passed, the email prompt is as follows. Different replies may be given due to different items

2, GPG installation and key generation

# command
pg --gen-key      # Generate key
gpg --list-keys   # Judge whether the key is generated successfully

1. GPG installation

Download address: https://www.gnupg.org/download/
After downloading, you can install it as a fool

Open cmd as an administrator and execute the command gpg --version to determine whether the installation is successful

2. Generate key

Open cmd as Administrator

Execute command: GPG -- Gen key
Enter user name / password

Enter o and the password setting will pop up

Get key

Send the key to the central warehouse server, and then upload it for authentication

gpg --keyserver keyserver.ubuntu.com --send-keys B34ACF782ABE8FD3
gpg --keyserver keyserver.ubuntu.com --recv-keys B34ACF782ABE8FD3

3, Configure the project and upload it

From February 2021, the repository does not support: https://oss.sonatype.org/#view-repositories

Use new address Repository:
https://s01.oss.sonatype.org/#view-repositories

Upload the central warehouse address configuration. Pay attention to using the new storage address

3.1. Add account and password configuration of central warehouse in settings.xml

   <!--  Account and password of central warehouse -->
        <server>
            <id>ossrh</id>
            <username>wangsong</username>
            <password>527W10N8C@123p</password>
        </server>

3.2. Add license, source code information, personal information and central warehouse configuration in pom.xml

  <!-- mvn clean deploy  -->
    <!-- licence -->
    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <!-- Source code information -->
    <scm>
        <url>https://github.com/wslxm/spring-boot-plus2</url>
        <connection>scm:https://github.com/wslxm/spring-boot-plus2.git</connection>
        <developerConnection>scm:https://github.com/wslxm/spring-boot-plus2.git</developerConnection>
    </scm>

    <!-- personal information,corresponding gpg to configure -->
    <developers>
        <developer>
            <name>wangsong</name>
            <email>1720696548@qq.com</email>
            <timezone>+8</timezone>
        </developer>
    </developers>
    
    <!-- Central warehouse configuration id Need to correspond settings.xml of server of id -->
    <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>

3.3 add packaging configuration to pom.xml

<!-- Packaging configuration -->
    <build>
        <finalName>xj-base-admin-${revision}</finalName>
        <plugins>
            <!-- java-doc to configure -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.4</version>
                <configuration>
                    <aggregate>true</aggregate>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration> <!-- add this to disable checking -->
                            <additionalparam>-Xdoclint:none</additionalparam>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- use source conduct jar pack-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- gpg to configure -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

4. Execute command upload to warehouse

Open cmd as an administrator to enter the project command and execute the command. Note that the terminal in the idea editor cannot execute the gpg command and cannot upload

mvn clean deploy

Seeing a lot of successful uploaded information means success

visit: https://s01.oss.sonatype.org/ Login to query

4, Verify and publish

4.1. Select the data to verify

4.2. Viewing verification results

If the verification fails, refer to the article: https://blog.csdn.net/pdsu161530247/article/details/105429597/

4.3 click publish


Just wait after the release. You can search the central warehouse in about 4 hours

Tags: Java Maven Spring Boot jar

Posted on Tue, 12 Oct 2021 16:13:30 -0400 by jcran