发布jar包到Maven中央仓库

开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第1天,点击查看活动详情

1、准备需要上传的仓库地址

以Github仓库为例: github.com/slightlee/m…

2、在 Sonatype 创建 Issue2.1 注册 Sonatype 账号

发布 Java 包到 Maven 中央仓库,首先需要在 Sonatype 网站创建一个工单(Issues)。 第一次使用这个网站的时候需要注册自己的帐号(这个帐号和密码需要记住,后面会用到)。

2.2 创建 Issue

注册账号成功后,根据你 Java 包的功能分别写上Summary、Description、Group Id、SCM url以及Project URL等必要信息,可以参见我之前创建的 Issue:OSSRH-86665。 创建完之后需要等待 Sonatype 的工作人员审核处理,按照要求处理就好。我这里没有使用域名按照提示在github上面新创建了个临时仓库用作验证,当 Issue 的 Status 变为RESOLVED后,就可以进行下一步操作了。

image.png

3、发表快照和发布

central-ossrhBot Central-OSSRH added a comment – Yesterday Congratulations! Welcome to the Central Repository! io.github.slightlee has been prepared, now user(s) demain can: Publish snapshot and release artifacts to s01.oss.sonatype.org Have a look at this section of our official guide for deployment instructions: central.sonatype.org/publish/pub… Depending on your build configuration, your first component(s) might be released automatically after a successful deployment. If that happens, you will see a comment on this ticket confirming that your artifact has synced to Maven Central. If you do not see this comment within an hour or two, you can follow the steps in this section of our guide: central.sonatype.org/publish/rel…

可参考官方配置: central.sonatype.org/publish/pub… central.sonatype.org/publish/pub…3.1 使用 GPG 生成公私钥对3.1.1 安装 gpg3.1.1.1 windows 安装 Gpg4win

Windows 系统,可以下载 Gpg4win 软件来生成密钥对。 Gpg4win 下载地址 安装后,执行命令 gpg –version 检查是否安装成功。

gpg –version复制代码

图形界面 image.png image.png

3.1.1.2 mac 安装 gpg

方式1: www.gnupg.org/download/ image.png 方式2: brew 安装

brew install gpg 复制代码3.1.2 生成密钥对3.1.2.1 命令生成gpg –gen-key复制代码

image.png 输入 Real name 、Email address 、输入 O 完毕之后弹窗提示输入保护密码

3.1.2.2 图形界面操作

image.png

3.1.3 查看公钥gpg –list-keys​文件地址: C:\Users\ming\AppData\Roaming\gnupg\pubring.kbx公钥: EA83BDE317D9301EE52D7BA75F7DE5F1222BC349复制代码

image.pngimage.png 图形界面方式查看 image.png

3.1.4 发布公钥到 PGP 密钥服务器

gpg –keyserver keyserver.ubuntu.com –send-keys 公钥

gpg –keyserver keyserver.ubuntu.com –send-keys EA83BDE317D9301EE52D7BA75F7DE5F1222BC349复制代码3.1.5 查看公钥是否发布成功

gpg –keyserver keyserver.ubuntu.com –recv-keys 公钥

gpg –keyserver keyserver.ubuntu.com –recv-keys EA83BDE317D9301EE52D7BA75F7DE5F1222BC349复制代码

image.png

3.2 Maven 配置3.2.1 settings.xml 配置            ossrh              your-jira-id      your-jira-pwd      ​​            ossrh              gpg                the_pass_phrase            ​复制代码3.2.2 pom.xml 配置 (SNAPSHOT版)    4.0.0​    io.github.slightlee    mybatis-plus-generator-simple        0.0.1-SNAPSHOT​    mybatis-plus-generator-simple    simple mybatis-plus-generator    https://github.com/slightlee/mybatis-plus-generator-simple.git​            17        17        17        17        UTF-8        3.5.3        3.5.2        2.3        5.9.1        0.0.35        3.10.1    ​​           …    ​​                            ossrh            https://s01.oss.sonatype.org/content/repositories/snapshots                            ossrh            https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/            ​            https://github.com/slightlee/mybatis-plus-generator-simple.git        https://github.com/slightlee/mybatis-plus-generator-simple.git        https://github.com/slightlee    ​                            The Apache Software License, Version 2.0            http://www.apache.org/licenses/LICENSE-2.0.txt            repo            ​                            demain_lee            [email protected]            demain_lee            https://github.com/slightlee            ​                Github        https://github.com/slightlee/mybatis-plus-generator-simple/issues    ​​            ​                                                    maven-compiler-plugin                ${maven-compiler-plugin.version}                                    ${java.version}                    ${project.build.sourceEncoding}                            ​                                        io.spring.javaformat                spring-javaformat-maven-plugin                ${spring.checkstyle.plugin}                                                            validate                        true                                                    validate                                                                        ​                                        org.apache.maven.plugins                maven-source-plugin                2.2.1                                                            attach-sources                                                    jar-no-fork                                                                                                    org.apache.maven.plugins                maven-javadoc-plugin                2.9.1                                                    -Xdoclint:none                                                                            attach-javadocs                                                    jar                                                                                                                org.apache.maven.plugins                maven-gpg-plugin                3.0.1                                                            sign-artifacts                        verify                                                    sign                                                                        ​            ​复制代码3.2.3 pom.xml 配置 (RELEASE版)    4.0.0​    io.github.slightlee    mybatis-plus-generator-simple        0.0.1-RELEASE​    mybatis-plus-generator-simple    simple mybatis-plus-generator    https://github.com/slightlee/mybatis-plus-generator-simple.git​            17        17        17        17        UTF-8        3.5.3        3.5.2        2.3        5.9.1        0.0.35        3.10.1    ​         …    ​​                            ossrh            https://s01.oss.sonatype.org/content/repositories/snapshots                            ossrh            https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/            ​            https://github.com/slightlee/mybatis-plus-generator-simple.git        https://github.com/slightlee/mybatis-plus-generator-simple.git        https://github.com/slightlee    ​                            The Apache Software License, Version 2.0            http://www.apache.org/licenses/LICENSE-2.0.txt            repo            ​                            demain_lee            [email protected]            demain_lee            https://github.com/slightlee            ​                Github        https://github.com/slightlee/mybatis-plus-generator-simple/issues    ​​            ​                                                    maven-compiler-plugin                ${maven-compiler-plugin.version}                                    ${java.version}                    ${project.build.sourceEncoding}                            ​                                        io.spring.javaformat                spring-javaformat-maven-plugin                ${spring.checkstyle.plugin}                                                            validate                        true                                                    validate                                                                        ​​                                        org.apache.maven.plugins                maven-source-plugin                2.2.1                                                            attach-sources                                                    jar-no-fork                                                                                                    org.apache.maven.plugins                maven-javadoc-plugin                2.9.1                                                    -Xdoclint:none                                                                            attach-javadocs                                                    jar                                                                                                                org.apache.maven.plugins                maven-gpg-plugin                3.0.1                                                            sign-artifacts                        verify                                                    sign                                                                        ​            ​                                release                                                                                                                    org.sonatype.plugins                        nexus-staging-maven-plugin                        1.6.13                        true                                                    ossrh                            https://s01.oss.sonatype.org/                            false                                            ​                                            org.apache.maven.plugins                        maven-gpg-plugin                        3.0.1                                                                                    sign-artifacts                                verify                                                                    sign                                                                                                        ​                                        ​复制代码3.3 打包部署上传3.3.1 SNAPSHOT版3.3.1.1 发布

执行命令 mvn clean deploy

mvn clean deploy复制代码3.3.2 查看上传的快照

仓库地址: s01.oss.sonatype.org 账号密码对应 issues.sonatype.org 注册的账号密码 可以看到快照版本

image.png

3.3.2 RELEASE版3.3.2.1 修改项目的版本命令

例如 0.0.1-RELEASE

mvn versions:set -DnewVersion=0.0.1-RELEASE复制代码3.3.2.2 发布

执行命令 mvn clean deploy -P release 注意:pom.xml 新增的 profiles 配置

mvn clean deploy -P release复制代码

image.png 可以看到 image.png

点击左侧的 Staging Repositories 可以看到刚才上传的版本,选中 点击上方的 Close –> Confirm 然后查看状态,当状态变成closed后, 操作 Release -> Confirm 。成功后会自动删除,过一段时间即可同步到 maven 中央仓库。

image.png image.png

完成之后会收到 邮件通知,Sonatype 上面也会有新的回复 。 image.png

io.github. slightlee的中央同步被激活。在你成功发布后,你的组件将在中央repo1.maven.org/maven2/,通常在30分钟内向公众开放,不过更新到search.maven.org 可能需要4个小时。

4、使用4.1 中央仓库搜索 jar包

central.sonatype.dev/ 搜索 mybatis-plus-generator-simple search.maven.org/ 搜索 mybatis-plus-generator-simplemaven仓库 搜索 mybatis-plus-generator-simple (截止目前未搜索到,不影响正常使用)

4.2 使用  io.github.slightlee  mybatis-plus-generator-simple  0.0.1-RELEASE复制代码@Testpublic void Test() { GeneratorInfoConfig generatorInfoConfig = new GeneratorInfoConfig.Builder().author(“demain_lee”).dbUrl( “jdbc:mysql://127.0.0.1:3306/xxx?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=GMT%2B8”) .username(“root”).password(“root”) // .packageName(“com.xxx.xxx”) // .outputDir(“C:\\Users\\ming\\”) // .mapperDir(“C:\\Users\\ming\\mapper”) .tablePrefix(“t_”).includeTable().excludeTable(“t_tag”).idType(IdType.ASSIGN_ID) // .templateEngine(new VelocityTemplateEngine()) // .enableSwagger() // .enableLombok() .build(); CodeGeneratorConfig.runCodeGenerator(generatorInfoConfig);}复制代码


比丘资源网 » 发布jar包到Maven中央仓库

提供最优质的资源集合

立即查看 了解详情