java jar brain Cave taught you upload the package to the central warehouse

The origin of brain-hole

As an open source developer tools, upload jar package to the central repository (Nexus Repository Manager), so the world can use the tools to develop their own is an important step

More demo please pay attention

springboot demo real items
java brain hole
java interview Collection
open source tools

Go forward hand in hand

1. Preparations

2. Start Task

  1. Login sonatype New Task
    image.png

  2. Fill in the application form
    image.png

  • Project: Select Community Support - Open Source Project Repository Hosting (OSSRH)
  • Question Type: Choose New Project
  • Summary: Project Description
  • Group Id: your personal domain name, the domain name if you do not, then groupId com.github can write your name or io.github your github github name.
  • ProjectURL: address eg your project: https://github.com/wqr503/lp-buffercall
  • SCM url: git address eg your project: https://github.com/wqr503/lp-buffercall.git
    other remained the same, and then click New
  1. View tasks
    after the new task will be able to see the following panel
    image.png

如果没看到任务,可以通过问题面板找到新创建的任务
image.png

  1. 耐心等待
    等待sonatype管理员响应你的任务,这个等待时间不一定,如果管理员响应了你的任务,会有邮件发到你的邮箱中,注意邮箱动态,下面我们看下管理员响应了你的任务
    image.png
    大概的意思就是你要在github上创建一个开放仓库,仓库名是:OSSRH-55148,这个仓库名字是管理员指定的,每个人都不一样,大家注意了。
    根据要求我们去到github创建一个开放仓库
    image.png

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mHCGKNmI-1581860961336)(https://upload-images.jianshu.io/upload_images/17317532-fa1f2da2b3c598ed.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
上面的警告忽略,那是因为我已经创建了这个仓库,所以提示名字已存在

  1. 告诉管理员
    我们创建好仓库后就可以留言给管理员了,我们回到sonatype, 在任务最下面有个备注

image.png
我们点开备注然后填写

I have created a public repo called OSSRH-55148, please confirm 

后点击添加

image.png

  1. 继续等待
    继续等待sonatype管理员响应你的任务, 管理员响应你的任务后就会看到
    image.png
    这句话的大概意思就是这个申请任务已经完成,你可以上传jar包到中央仓库了

2. 准备JAR包

  1. 下载加密工具gpg
    下载网址 : https://www.gpg4win.org/download.html

windows 版本的gpg工具, 关注下面的公众号,回复"gpg"就可获取云盘下载链接

下载后默认安装就可以了, 安装完成后打开这个
image.png
选择新建密钥对
image.png
image.png
按照要求输入所需的消息然后点击新建
image.png
然后会要求输入两次密码,要记住这个密码,后面上传jar要用
image.png
创建成功后选择将公钥上传到服务器,最后点击完成
image.png
然后就能看到刚创建的密钥,最后我们检查一下密钥是否已经上传到服务器
image.png
选择在服务器上查找, 输入刚开始的名字,点击搜索,如果能搜索到条目证明上传成功
image.png

  1. 修改maven配置
    首先我们找到maven的全局配置settings.xml,通常是在用户文件夹下.m2
    image.png

打开settings.xml文件,找到servers标签, 修改如下

    <servers>
        <server>
            <id>sonatype-nexus-snapshots</id>
            <username>Sonatype网站对应的账号</username>
            <password><![CDATA[Sonatype网站对应的密码]]></password>
        </server>
        <server>
            <id>sonatype-nexus-releases</id>
            <username>Sonatype网站对应的账号</username>
            <password><![CDATA[Sonatype网站对应的密码]]></password>
        </server>
    </servers>

到此maven的配置就准备完毕

  1. 修改项目的pom文件
<modelVersion>4.0.0</modelVersion>

    <!--    中央仓库的父级pom-->
    <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>7</version>
    </parent>

    <!-- sonatype上的groupID -->
    <groupId>com.github.wqr503</groupId>
    <artifactId>lp-jpa-cquery</artifactId>
    <!-- 注意这里不能有 -SNAPSHOT -->
    <version>1.1.1</version>

    <name>lp-jpa-cquery</name>
    <url>https://github.com:wqr503/lp-jpa-cquery</url>
    <description>jpa条件查询</description>

    <!-- 项目地址描述 -->
    <scm>
        <connection>scm:git:[email protected]:wqr503/lp-buffercall.git</connection>
        <developerConnection>scm:git:[email protected]:wqr503/lp-buffercall.git</developerConnection>
        <url>[email protected]:wqr503/lp-buffercall.git</url>
    </scm>

    <!-- 开发者描述 -->
    <developers>
        <developer>
            <name>yourName</name>
            <email>yourEmail</email>
            <roles>
                <role>developer</role>
            </roles>
        </developer>
    </developers>

    <!--开源协议-->
    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <properties>
        <jdk.version>9</jdk.version>
    </properties>

    <build>
        <plugins>
            <!--项目基础配置-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <!--配置生成源码包-->
            <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</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!--发布代码Jar插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.7</version>
            </plugin>

        </plugins>
    </build>

    <!--项目打包相关配置-->
    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <!-- 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.9.1</version>
                        <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>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <distributionManagement>

        <!--上传仓库-->
        <snapshotRepository>
            <id>sonatype-nexus-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>

        <!--上传仓库-->
        <repository>
            <id>sonatype-nexus-releases</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
        </repository>

    </distributionManagement>

修改完后执行命令

mvn clean deploy -P sonatype-oss-release -Dgpg.passphrase=设置gpg的密码

打包完成后,会要求你输入密码,这个密码就是之前gpg上输入的密码
image.png
校验成功后就会上传jar包到中央仓库,下面就是成功的界面
image.png

  1. release 中央仓库
    下面我们登录中央仓库,登录的账号名和密码就是Sonatype网站对应的账号和密码,登录成功后就会看见我们刚上传的jar包
    image.png
    这里看到状态的时open状态,其实这种状态这是暂存状态,其他人是看不到,我们要把这个repository release 了,其他人才能看到你上传的jar包, 首先我们要close repository,然后等待几分钟,等待Relase按钮亮起
    image.png
    image.png
    点击release,没有任何红点就表示成功了,以下是成功页面
    image.png
    现在别人就能在中央仓库看到你的包了
    image.png
    国内的中央仓库镜像同步要好几天甚至一个星期,这个要耐心等待。以上就是全部内容了

# Public Number
five minutes to understand cutting-edge technology, big data, micro-service, regional chain, providing cutting-edge technology java dry goods, independent game production technology sharing

Five minutes technology

If this article helpful to you Give me a star
image.png

Published 27 original articles · won praise 0 · Views 516

Guess you like

Origin blog.csdn.net/wqr503/article/details/104349653
Recommended