做者:小傅哥
博客:https://bugstack.cn - 原创系列专题案例
html
沉淀、分享、成长,让本身和他人都能有所收获!😄
(19年12月)最近想基于Spring Boot作个开源共享项目,开发一个分布式任务DcsSchedule中间件能够把Schedule加强。那么遇到一个问题但愿把Jar包发包到Maven中央仓库,这样须要使用的用户就能够直接引入。java
内容 | 备注 | |
---|---|---|
1 | 申请Github账号: https://github.com | 用于上传开源代码:https://github.com/fuzhengwei... |
2 | GPG生成密钥工具: https://gpg4win.org/download.... | 在后续流程中下载安装生成密钥并上传置服务器,本文使用的服务器是:hkp://keyserver.ubuntu.com:80 |
3 | 工单系统: https://issues.sonatype.org | 负责申请上传资格及完成第一次上传,后续更新不须要使用,至关于一个启动装置 |
4 | 构件仓库: https://oss.sonatype.org | 上传的jar包会先存放到这里,在这里进行 Release 后便可发布到maven中央仓库,也能够本地设置自动发布 |
5 | 镜像仓库: http://search.maven.org | 最终成功发布的jar能够在这里搜到 |
6 | Maven仓库:https://mvnrepository.com | 通过几个小时耐心的等待会在Maven仓库中搜到 |
7 | 阿里云仓库:https://maven.aliyun.com | 阿里云的仓库会同步的快一些 |
8 | 我的域名:https://bugstack.cn | 这里主要用于工单资格验证(Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-53637 (Fastest)) |
咱们须要一个GPG环境,用来对上传的文件进行加密和签名,保证你的jar包不被篡改git
1991年,程序员Phil Zimmermann为了避开政府监视,开发了加密软件PGP。这个软件很是好用,迅速流传开来,成了许多程序员的必备工具。可是,它是商业软件,不能自由使用。因此,自由软件基金会决定,开发一个PGP的替代品,取名为GnuPG。这就是GPG的由来。
生成密钥(可使用命令行生成,也能够直接在操做界面生成)程序员
当建立完工单后,会收到信息反馈(国外与咱们有时间差,半夜的时候他们审核的更快);github
```java 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 指向问题域:https://issues.sonatype.org/b...spring

在域名验证截图,回复到问题下,人工审核会进行验证处理apache

验证成功后,会收到邮件回复,也能够在issues看到{意思就说去发布你的Jar吧宝贝,发布完告诉我一下(来这里回复下,我就让你用了)}ubuntu
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.