微信公众号:bugstack虫洞栈 | 沉淀、分享、成长,专注于原创专题案例,以最易学习编程的方式分享知识,让自己和他人都能有所收获。目前已完成的专题有;Netty4.x实战专题案例、用Java实现JVM、基于JavaAgent的全链路监控、手写RPC框架、架构设计专题案例[Ing]等。
(19年12月)最近想基于Spring Boot做个开源共享项目,开发一个分布式任务DcsSchedule中间件可以把Schedule增强。那么遇到一个问题希望把Jar包发包到Maven中央仓库,这样需要使用的用户就可以直接引入。
内容 | 备注 | |
---|---|---|
1 | 申请Github帐号: github.com | 用于上传开源代码: github.com/fuzhengwei/… |
2 | GPG生成密钥工具: gpg4win.org/download.ht… | 在后续流程中下载安装生成密钥并上传置服务器,本文使用的服务器是:hkp://keyserver.ubuntu.com:80 |
3 | 工单系统: issues.sonatype.org | 负责申请上传资格及完成第一次上传,后续更新不需要使用,相当于一个启动装置 |
4 | 构件仓库: oss.sonatype.org | 上传的jar包会先存放到这里,在这里进行 Release 后即可发布到maven中央仓库,也可以本地设置自动发布 |
5 | 镜像仓库: search.maven.org | 最终成功发布的jar可以在这里搜到 |
6 | Maven仓库: mvnrepository.com | 经过几个小时耐心的等待会在Maven仓库中搜到 |
7 | 阿里云仓库: maven.aliyun.com | 阿里云的仓库会同步的快一些 |
8 | 个人域名: bugstack.cn | 这里主要用于工单资格验证(Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-53637 (Fastest)) |
我们需要一个GPG环境,用来对上传的文件进行加密和签名,保证你的jar包不被篡改
1991年,程序员Phil Zimmermann为了避开政府监视,开发了加密软件PGP。这个软件非常好用,迅速流传开来,成了许多程序员的必备工具。但是,它是商业软件,不能自由使用。所以,自由软件基金会决定,开发一个PGP的替代品,取名为GnuPG。这就是GPG的由来。
当创建完工单后,会收到信息反馈(国外与我们有时间差,半夜的时候他们审核的更快);
Do you own the domain itstack.org? If so, please verify ownership via one of the following methods: Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-53637 (Fastest) Setup a redirect to your Github page (if it does not already exist) If you do not own this domain, please read: http://central.sonatype.org/pages/choosing-your-coordinates.html You may also choose a groupId that reflects your project hosting, in this case, something like io.github.fuzhengwei or com.github.fuzhengwei Would you like to use a free managed security reporting service (recommended)? Put https://hackerone.com/central-security-project/reports/new as your project's security issue reporting URL. We'll take care of the rest. For more details on the Central Security Project, visit https://www.sonatype.com/central-security-project 复制代码
配置域名验证签名;TXT 指向问题域: issues.sonatype.org/browse/OSSR…
在域名验证截图,回复到问题下,人工审核会进行验证处理
验证成功后,会收到邮件回复,也可以在issues看到{意思就说去发布你的Jar吧宝贝,发布完告诉我一下(来这里回复下,我就让你用了)}
org.itstack.middleware has been prepared, now user(s) fuzhengwei can: * Deploy snapshot artifacts into repository https://oss.sonatype.org/content/repositories/snapshots * Deploy release artifacts into the staging repository https://oss.sonatype.org/service/local/staging/deploy/maven2 * Release staged artifacts into repository 'Releases' please comment on this ticket when you promoted your first release, thanks 复制代码
接下来等待发布Jar包成功后,到这里回复并收到反馈,如下(证明你成功了!);
Central sync is activated for org.itstack.middleware. After you successfully release, your component will be published to Central, typically within 10 minutes, though updates to search.maven.org can take up to two hours. 复制代码
<server> <id>sonatype-nexus-snapshots</id> <username>https://issues.sonatype.org的账号</username> <password>https://issues.sonatype.org的密码</password> </server> <server> <id>sonatype-nexus-staging</id> <username>https://issues.sonatype.org的账号</username> <password>https://issues.sonatype.org的密码</password> </server> <server> <id>ossrh</id> <username>https://issues.sonatype.org的账号</username> <password>https://issues.sonatype.org的密码</password> </server> 复制代码
<mirror> <id>alimavenrepository</id> <name>aliyun maven repository</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> 复制代码
<profile> <id>ossrh</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <gpg.executable>D:/Program Files (x86)/GnuPG/bin/gpg.exe</gpg.executable> <gpg.passphrase>上面生成的密钥密码:bugstack.cn</gpg.passphrase> <gpg.homedir>{找到dir:cmd->gpg --list-key}C:/Users/fuzhengwei/AppData/Roaming/gnupg</gpg.homedir> </properties> </profile> 复制代码
<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> <scm> <url>https://github.com/fuzhengwei/schedule-spring-boot-starter</url> <connection>https://github.com/fuzhengwei/schedule-spring-boot-starter.git</connection> <developerConnection>https://github.com/fuzhengwei/schedule-spring-boot-starter</developerConnection> </scm> <developers> <developer> <name>fuzhengwei</name> <email>184172133@qq.com</email> <url>https://github.com/fuzhengwei/schedule-spring-boot-starter</url> </developer> </developers> <distributionManagement> <snapshotRepository> <id>ossrh</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement> 复制代码
<!-- 发布Jar到Maven仓库 Begin --> <!--生成Source jar文件--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <!--生成Javadoc,关闭doclint,避免注解检查不通过--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.9.1</version> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> <configuration> <additionalparam>-Xdoclint:none</additionalparam> </configuration> </execution> </executions> </plugin> <!--Maven GPG插件用于使用以下配置对组件进行签名--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId> <version>1.5</version> <executions> <execution> <id>sign-artifacts</id> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin> <!--Nexus Staging Maven插件是将组件部署到OSSRH并将其发布到Central Repository的推荐方法--> <plugin> <groupId>org.sonatype.plugins</groupId> <artifactId>nexus-staging-maven-plugin</artifactId> <version>1.6.7</version> <extensions>true</extensions> <configuration> <serverId>ossrh</serverId> <nexusUrl>https://oss.sonatype.org/</nexusUrl> <autoReleaseAfterClose>true</autoReleaseAfterClose> </configuration> </plugin> <!-- release plugin,用于发布到release仓库部署插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.4.2</version> </plugin> <!-- 发布Jar到Maven仓库 End --> 复制代码
Central sync is activated for org.itstack.middleware. After you successfully release, your component will be published to Central, typically within 10 minutes, though updates to search.maven.org can take up to two hours. 复制代码