一、重点网站
1.https://issues.sonatype.org 此网站的主要目的是检查你要上传的groupId是否是唯一的,且是否是你所有的
2.https://oss.sonatype.org 此网站的主要目的是发行你上传的jar
3.http://search.maven.org 发布jar后,此网站会最先获取到你上传的jar信息(但是也需要等待近2小时)
注:这三个网站是按顺序来的
二、注册账号,解决问题
打开https://issues.sonatype.org。注册一个账号,记住你注册的账号密码,然后登陆。
上传自己的jar到maven中心仓库是从解决Issues(问题)开始的。所以我们点击create。
填写完毕之后,状态一般是Unresolved状态。
然后静静的等待,一般工作人员会在晚上回复你(因为有时差),回复的问题也一般会跟你的Group Id是否合法有关系。比如回复我的,就是建议把我的Group Id改成com.github.satant,你更改完后回复工作人员,如果收到以下回复,则说明已经可以上传jar了。
三、上传jar
1.修改POM文件
这里我们项目pom文件中的groupId一定要改成我们审核通过的groupId,version就使我们上传的版本。
同时增加如下内容
<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/satant/pj.mybatis</url>
<!-- 我填的是项目的下载路径 -->
<connection>https://github.com/satant/pj.mybatis.git</connection>
</scm>
<developers>
<developer>
<!-- 开发人员名称 -->
<name>dear_satant</name>
<!-- 开发人员邮箱 -->
<email>dear_satant@163.com</email>
</developer>
</developers>
<profiles>
<profile>
<id>release</id> <!-- 执行release时会依次执行下方的所有插件 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Source -->
<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>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<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>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>a</id> <!-- 此处id我们对应下方servers节点中的id -->
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>b</id> <!-- 此处id我们对应下方servers节点中的id -->
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
2.修改系统默认maven的settings.xml文件,增加以下内容
<servers>
<server>
<id>a</id> <!-- 此处id对应上方的id -->
<username>第一个网址https://issues.sonatype.org上注册的用户名</username>
<password>第一个网址https://issues.sonatype.org上注册的密码</password>
</server>
<server>
<id>b</id> <!-- 此处id对应上方的id -->
<username>第一个网址https://issues.sonatype.org上注册的用户名</username>
<password>第一个网址https://issues.sonatype.org上注册的密码</password>
</server>
</servers>
3.下载GPG工具
如果是使用的windows,可以下载gpg4win,地址:https://www.gpg4win.org/download.html,安装后在命令行中执行gpg --version可以看到版本,此处我用的是2.3.3。我用3.0+版本上传时失败了,我不知道为什么所有退回了2.3.3。
接着在命令行中执行 gpg --gen-key生成密钥,过程中需要填写名字、邮箱等,其他步骤可以使用默认值,不过有个叫:Passphase的参数需要记住,这个相当于是是密钥的密码,下一步发布过程中进行签名操作的时候会用到。
就是这个界面,这里输入的密码一定要记住,后面上传的时候会用到。
生成结束之后会告诉你一传代码其中我画出的385C01F1就是我们的密钥。
这时,我们准备上传jar,在命令行中切换到我们项目pom.xml文件所有的目录。
然后执行 mvn clean deploy -P release
当看到这个界面时,表示我们已经上传成功了。
然后我们上传密钥:gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 385C01F1(这里填你自己生成的密钥)
上传完成之后打开第二个网址:https://oss.sonatype.org/
点击右上角log in 输入账号密码,就是第一个网址https://issues.sonatype.org 中注册的账号密码。随后单击左侧Staging Repositories,拉到底,就能够看到我们刚刚上传的jar包了。
选中组件单击close,弹出框中单击confirm,等待关闭完成,大约30秒。
完成之后选中组件,单击Release,弹出框选择confirm就能完成发布了。
随后我们上传的组件会在这个列表中消失,大约1小时后我们的jar就能在http://search.maven.org上查到。
好啦!至此,3篇文章都讲完了,如果还有人能看到这里,说明我的辛苦没有白费,感谢你们,我也会努力写出更多好文章的!