Publish your own Jar to the Maven Central Warehouse with one click

Doing java development is of course inseparable from jar package management. I don’t know when I always want to package my own jar package
and then publish it to the maven central warehouse for others to use.

hhh I feel that writing a jar package tool and being used by many people is a very good and very happy thing.

Finally had this opportunity, and time. SpringBoot staterBased on the scene starter, you can easily define your own stater components, and even publish them to the maven repository. for everyone to use.

I summed up and wrote a tool library, stater, as a programmer I have worked for many years.

Github address

Based on it, you can easily develop SpringBoot WEB API and improve efficiency. Don't care about some cumbersome things anymore. Duplicate work, but focus on business.

Back to the topic, this article is based on mine, let the stater talk about it. How to publish the self-defined stater to the maven central warehouse.

Register sonatype account

Enter issues.sonatype.org to register your own account, based on this platform, quickly publish to the maven warehouse

After the registration is complete, remember the account password, and later release requires authorization

Create your own maven project work order

After the registration is complete, we create ourselves, publish maventhe project, and click New

Project selection: Community Support - Open Source Project Repository Hosting (OSSRH)

Question type selection: New Project

* is a required item, the rest can be left blank or keep the default, and then create a new work order to wait for the administrator to review

Project Address Fill in a Github warehouse address of your project. It is still emphasized here to fill in the group id. The group id needs to be filled in according to your own domain name or open source warehouse address.

Later in the question - my report can track the audit status of the issue

Waiting for administrator review. After the audit is completed, the administrator will prompt you to verify that the domain name is yours or prove that the gitee or github space is yours

close maven work order project

After the maven work order project is approved, there will be an email reminder.

After creating a successful issue, you need to wait for the Sonatype staff to review it. The review time is about a few minutes (I was 5 minutes, it seemed that someone took a few hours...), after the review is passed, the Status of the issue will change to Resolved, and you can proceed to the next step Operated

You click on the question - find your own newly created project

Then click the Respond button to open the ticket and let the administrator verify it.

Wait for the verification to complete, and the administrator will then reply to you that the verification is successful, which means that your work order has passed and you can upload the project

If you use a domain name, the administrator will ask you to add a TXT resolution to your domain name, and then he will verify it:

No problem, you can close the question at this time

project configuration

maven configuration

Configure your registered issues.sonatype.org account password in your maven configuration file

settings.xmlThe servers node configuration of the file under the maven conf folder is as follows

 <server>
      <id>snapshots</id>
      <username>kenx</username>
      <password>xxxx</password>
    </server>
    <server>
      <id>releases</id>
      <username>kenx</username>
      <password>xxxx</password>
    </server>
    <server>
      <id>ossrh</id>
      <username>kenx</username>
      <password>xxx</password>
    </server>

Key configuration

Use gpg to generate a secret key

Uploading projects requires secret key signature authentication. A password needs to be generated locally. And upload the public key to the service.

generate key

gpg --gen-key

After running, gpg requires you to select the encryption algorithm, expiration time, etc., and you can directly select the default values. Through comparison, it is found that running the gpg --gen-key command in versions above gpg 2.0 will skip these steps.

Afterwards, gpg requires you to enter your name, email address, and the key Passphrase (this password should be remembered by yourself, it will be useful later), and you can enter it in sequence. Then gpg generates a pair of keys for you.

view key

gpg --list-keys

There is a hexadecimal number under the pub field, that is the ID of this key

Then we need to upload this secret key to the public key server, using the following command:

gpg --keyserver keyserver.ubuntu.com --send-keys 秘钥ID

Verify that the upload was successful to the server:

gpg --keyserver keyserver.ubuntu.com --recv-keys 秘钥ID

If the output results of the two commands are as follows, it means success:

In this way, the configuration of the secret key is completed.

Modify the project pom configuration

Next we need to configure the pom file in our project,

<groupId>cn.soboys</groupId>
    <artifactId>rest-api-spring-boot-starter</artifactId>
    <version>1.3.0</version>
    <packaging>jar</packaging>
    <name>rest-api-spring-boot-starter</name>
    <description>SpringBoot Easy Fast Rest WEB 提高SpringBoot Web开发工作效率 RestFull API使用 全局错误拦截,参数校验, 错误国际化 ,自定义错误响应 ,业务异常断言 ,Redis 工具库使用 ,RestTemplate 请求工具 ,日志使用 ,集成mybatisPlus一键代码生成</description>
    <url>https://github.com/coder-amiao/rest-api-spring-boot-starter</url>

    <!-- 项目设定 -->
    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <gpg.passphrase>1234qwer</gpg.passphrase>
        <gpg.keyname>E933FBC878FB2EC0900A2ABAF79C3CD9E9E6A8EF</gpg.keyname>
        <gpg.homedir>/Users/xiangyong/.gnupg</gpg.homedir>
    </properties>



    <!-- 许可证信息,这里是Apache 2.0的许可证,大家根据实际情况修改 -->
    <licenses>
        <license>
            <name>The Apache Software License, Version2.0</name>
            <url>https://www.apache.org/licenses/</url>
            <distribution>repo</distribution>
        </license>
    </licenses>


    <!--   开发人员信息         -->
    <developers>
        <developer>
            <name>三时</name>
            <email>[email protected]</email>
        </developer>
    </developers>

    <!--   项目仓库信息         -->
    <scm>
        <connection>scm:git:https://github.com/zw201913/jtile38.git</connection>
        <developerConnection>https://github.com/coder-amiao/rest-api-spring-boot-starter</developerConnection>
        <url>https://github.com/coder-amiao/rest-api-spring-boot-starter.git</url>
        <tag>v${project.version}</tag>
    </scm>

    <!-- 中央仓库地址配置,不需要修改 -->
    <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.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <!-- Source -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Javadoc工具 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.4</version>
                <configuration>
                    <additionalJOptions>
                        <additionalJOption>-Xdoclint:none</additionalJOption>
                    </additionalJOptions>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- GPG -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.6</version>
                <configuration>
                    <gpgArguments>
                        <arg>--pinentry-mode</arg>
                        <arg>loopback</arg>
                    </gpgArguments>
                </configuration>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Note that the configured groupId must be consistent with the maven project work order you created earlier

pom.xml must include basic information such as name, description, url, licenses, developers, scm, etc., using Maven's profile function, only when releasing, create source code packages, document packages, and use GPG for digital signatures.

In addition, the id in snapshotRepository and repository must be consistent with the server id in setting.xml.

If it is a multi-module project, you only need to declare these in the parent pom.xml, and only need to modify some corresponding information in the child pom.xml, such as the name tag.

Project release

Next you can publish the project using deploy

or command

mvn clean deploy

Publish the project to the central repository

The above steps are just to transfer the project to Sonatype, and it has not been released yet.

Enter s01.oss.sonatype.org, log in, the account is the user name and password of the previously registered account

Click Staging Repositories next to it to see our published projects.

Check the item and click the close button to start the item verification.

Then click the active label below to view the progress of the close:

If All rules passed: Central Sync Requirement is displayed, it means that the verification has passed and can be released.

If the process button is gray, or cannot be clicked, just repeat the refresh and wait (it may be due to other reasons such as the network). Then repeat the above steps. can

Then click the release button above to publish to the central warehouse.

After completion, about 2 hours later, you can find your published project on search.maven.org !

Summary

After publishing the project, if the groupId remains unchanged, we don't need to apply for a work order.

Just repeat some of the key steps in steps 2, 3, and 4 above.

The above settings.xml has configured servers,

There is no need to configure it again, that is, the second step of configuring settings.xml can be omitted. The secret key has already been generated, and there is no need to generate it again, that is, the third step of secret key generation is also unnecessary. However, if you change the computer, you need to reconfigure settings.xml and regenerate and upload the secret key.

Pay attention to the official account, the programmer will continue to output high-quality content at three o'clock , hoping to bring you some inspiration and help

Guess you like

Origin blog.csdn.net/u011738045/article/details/131620029