义乌外贸网站建设来啦厦门seo公司
maven中央仓库是一个开放的仓库,所以我们也可以把自己开发的jar推送到远程仓库,这样可以直接引入pom依赖使用我们的库。
准备工作
● 需要一个github账号(程序员必备)
● 网络代理(涉及到的网站通常没版本在国内直接访问,所以最好使用代理)
其他不需要准备什么了,按照以下的步骤依次执行就行。
主要流程:在github上创建项目 - 注册sonatype账号 - 项目申请 - 安装PGP - 修改仓库信息 - 推送到maven仓库。
在github上创建自己的项目
创建一个项目,设置成public即可。
注册sonatype账号
https://issues.sonatype.org/secure/Signup!default.jspa
注册的信息没有特殊要求,一般和github账号保持一致,也容易记。
这个网站和我们平常用的jira一样,方便协同合作。
项目申请
新建一个【Community Support - Open Source Project Repository Hosting (OSSRH)】类型的问题,主要用于验证github项目是否有效。
这个页面中需要填group.id等信息,如下:
Group Id是自己域名的反写,如果没有域名可以使用github地址,例如:io.github.casuallc。
提示:https://casuallc.github.io/ 这个地址是基于github创建的自己博客的地址,如果没有可以创建下。
Project URL 是github上的项目地址:https://github.com/casuallc/admq-spring-boot-starter
SCM url是git地址:https://github.com/casuallc/admq-spring-boot-starter.git
填写完成后,会有人在这个问题的评论里联系你。
验证Github项目有效性
进入创建的问题,大概等几分钟后就有机器人联系你的,会留下以下的评论。
这个是让你在github上创建一个空的项目,创建完评论下就行(不评论估计也行,,)。
之后在创建的问题下会有如下评论,表示你已经可以准备发布项目到maven仓库了。
安装GPG
这个工具是用来加密构建的jar、pom、source和doc的,理论上是必须的,但是我没验证。可以先跳过,如果后边有报错再安装也行。
https://gpg4win.org/ 在这里可以下载对应操作系统安装包,我是在window下安装的,直接点点点就好了。。。
这里有一点需要注意的是,这个网站会让你选择是不是捐赠,有钱的话就捐点,没钱的话不捐也行。
安装完成后打开,在【文件】中选择【New OpenPGP Key Pair…】
名字、邮件地址和github上的保持一致吧。
创建完成后:
然后右键创建好的证书,选择【在服务器上发布】。
修改项目License信息
这个不是必须的,但通常会在pom中添加Apache License信息和一些用户信息。
<licenses><license><name>Apache License, Version 2.0</name><url>http://www.apache.org/licenses/LICENSE-2.0.txt</url><distribution>repo</distribution></license></licenses><scm><connection>https://github.com/casuallc/admq-spring-boot-starter.git</connection><url>https://github.com/casuallc/admq-spring-boot-starter</url></scm><developers><developer><name>clooker</name><email>clooker@163.com</email><roles><role>Developer</role></roles><timezone>+8</timezone></developer></developers>
添加仓库和认证信息信息
在项目的pom.xml中添加以下内容
<profiles><profile><id>release</id><build><plugins><plugin><artifactId>maven-source-plugin</artifactId><executions><execution><id>attach-sources</id><goals><goal>jar</goal></goals></execution></executions></plugin><plugin><artifactId>maven-javadoc-plugin</artifactId><version>${maven-javadoc-plugin.version}</version><executions><execution><id>attach-javadocs</id><goals><goal>jar</goal></goals></execution></executions><configuration><source>8</source><doclint>none</doclint></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>1.6</version><executions><execution><id>sign-artifacts</id><phase>verify</phase><goals><goal>sign</goal></goals></execution></executions></plugin><plugin><groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId><version>${nexus-staging-maven-plugin.version}</version><extensions>true</extensions><configuration><serverId>ossrh</serverId><nexusUrl>https://s01.oss.sonatype.org/</nexusUrl><autoReleaseAfterClose>true</autoReleaseAfterClose></configuration></plugin></plugins></build></profile>
</profiles>
在maven的settings.xml中添加sonatype上注册的账户信息。
<server><id>ossrh</id><username>clooker</username><password>xxxx</password>
</server>
注意:项目pom文件中org.sonatype.plugins插件下的serverId要和maven settings.xml中的id保持一致。
推送项目到maven仓库
执行 maven clean deploy -Prelease
org.sonatype.plugins 这个插件会自动推送到maven仓库,然后执行close、release操作,不需要手动在https://s01.oss.sonatype.org/上执行了。
之前的流程:
登录https://s01.oss.sonatype.org/,用户名密码和sonatype一样
选择:Staging Repositories
刷新后,选择刚才自己提交的项目,依次点击:Close和Release。
查看自己的项目
等待一段时间后就能在maven仓库看到自己的项目了,我这里是推送成功就能看到了。
https://s01.oss.sonatype.org/content/repositories/releases/io/github/casuallc/admq-spring-boot-starter/
其他
需要注意的是release的版本不能相同,也就是已经release的jar就不能修改了,所以每次release需要修改版本号。
如果出现401、403等问题,通常是GPG没有安装好,或者maven-gpg-plugin插件的版本不对,或者是在sonartype上注册账号需要等一段时间才会生效。