maven发布项目到中央仓库

maven发布自己的项目到中央仓库

1.注册sonatype网站账号

https://issues.sonatype.org/secure/Signup!default.jspa

在这里插入图片描述

注册成功之后然后直接登录就行了

2.新建新的问题(issues)

在这里插入图片描述

在这里插入图片描述

这个组id,可以是io.github.你的GitHub用户名 或者你的域名 反着来 打个比方,如果是 你的域名是 mhb.icu 那么就是 icu.mhb

在这里插入图片描述

然后就等待工作人员评论

等到工作人员说

在这里插入图片描述

这种说认证通过了,可以去上传jar包到中央仓库了

3.配置pom信息

配置maven信息

 <server>
   <id>ossrh</id>
   <username>你sonatype账号</username>
   <password>sonatype 密码</password>
</server>

这个放在servers标签下下

添加个人信息

 <name>mybatis-plus-join</name>
 <description>A multi-table plugin for Mybatis Plus.</description>
 <url>https://github.com/bobo667/mybatis-plus-join</url>

   <developers>
        <developer>
            <id>mhb</id>
            <name>mahuibo</name>
            <email>mhb0409@qq.com</email>
        </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>

这里看自己项目是啥版权就用啥版权这里我用的是 Apache License 2.0

添加 scm信息

 <scm>
    <connection>https://github.com/bobo667/mybatis-plus-join.git</connection>
    <url>https://github.com/bobo667/mybatis-plus-join</url>
 </scm>

connection 是连接到你github的地址

url 是你github 项目地址

添加插件

        <profile>
            <id>release</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <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>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <configuration>
                            <show>private</show>
                            <nohelp>true</nohelp>
                            <charset>UTF-8</charset>
                            <encoding>UTF-8</encoding>
                            <docencoding>UTF-8</docencoding>
                            <additionalparam>-Xdoclint:none</additionalparam>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <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>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.7.0</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                        </configuration>
                    </plugin>
                    <!--Release -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-release-plugin</artifactId>
                        <version>2.5.1</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <version>2.8.2</version>
                        <executions>
                            <execution>
                                <id>default-deploy</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>deploy</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-scm-plugin</artifactId>
                        <version>1.8.1</version>
                    </plugin>
                </plugins>
            </build>
            <!-- 这里配置的ossrh要与settings.xml的一致,不然发布会出错 -->
            <distributionManagement>
                <snapshotRepository>
                    <id>ossrh</id>
                    <name>Sonatype Nexus Snapshots</name>
                    <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
                </snapshotRepository>
                <repository>
                    <id>ossrh</id>
                    <name>Nexus Release Repository</name>
                    <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                </repository>
            </distributionManagement>
        </profile>

注意 distributionManagement 下面的id一定要和你 maven setting里面的id配置的一模一样

完整的pom.xml参考我 gitee 或者github
https://gitee.com/mhb0409/mybatis-plus-join
https://github.com/bobo667/mybatis-plus-join

4.下载GPG加密

下载地址:https://www.gnupg.org/download/

下载自己需要的版本就行了

安装完成后验证以下,输入如下命令

gpg --version

在这里插入图片描述

出现类似这种信息就是安装成功了

生成密钥的命令 gpg --gen-key ,过程中需要使用到姓名、邮箱等信息,这里的配置最好和Sonatype 注册信息、pom文件配置信息保持一致,以免不必要的麻烦。

生成的过程中,会有个弹框要求输入Passphase 信息,这个是密钥的密码,同样需要记牢。发布签名的过程中会用得到。

使用 gpg --list-keys 命令查询配置好的公私钥信息,

使用

 gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 刚刚生成的公钥 

 # 例如:

 gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 21A78F78088627FBFDF44B0AF454587F5B01700C

将公钥信息发送到ubuntu.com服务器,后续推送maven仓库会做校验。

上传后可以使用以下命令查询

gpg --list-keys

gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
gpg: next trustdb check due at 2022-03-05
C:/Users/11879/AppData/Roaming/gnupg/pubring.kbx
------------------------------------------------
pub   rsa2048 2020-03-05 [SC] [expires: 2022-03-05]
      78C42AF52F1A261BC7116AD1EC495633FCD63F52
uid           [ultimate] imcoder <1187931389@qq.com>
sub   rsa2048 2020-03-05 [E] [expires: 2022-03-05]


pub   rsa2048 2020-03-05 [SC] [expires: 2022-03-05]
      21A78F78088627FBFDF44B0AF454587F5B01700C
uid           [ultimate] imcoder <1187931389@qq.com>
sub   rsa2048 2020-03-05 [E] [expires: 2022-03-05]

5.上传到中央仓库

mvn clean deploy -P release

# 这里的 -P release应该就是对应的
<profile>
    <id>release</id>
</profile>

之后出现

在这里插入图片描述

这种一堆Uploading信息,然后显示成功信息就代表上传成功了

发布成功后我们就可以在

在这里插入图片描述

看到我们刚刚发布上去的jar包

1.先点击close
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PFiDnSJY-1632653169591)(http://mhba.work/upload/2021/09/image-80652dfc65614a938b124d74b386a7a8.png)]

过个几分钟点击
image.png

然后就可以查询到
image.png

然后我们到 https://search.maven.org/ 去查看我们的项目,如果没有查到也不要着急,同步需要一段时间,我的1.0.1版本就还没有查到,但是已经可以依赖了。

加个广告:
mybatis-plus 的多表无侵入插件,需要的老板请去看看
https://gitee.com/mhb0409/mybatis-plus-join

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值