maven 第一次发布jar到中央仓库
一、步骤
1.注册
https://issues.sonatype.org/secure/Signup!default.jspa
2.登录
https://issues.sonatype.org/login.jsp
3.创立issue
https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134创立好的就是如下这种
image.png
创立完之后会收到一封邮件,而后我们创立好的issue就如下,后面跟官方的少量交互和问答基本上都是在这里完成https://issues.sonatype.org/browse/OSSRH-49415
4.创立完毕后等待通知
我这里遇到这样的一个问题,后来收到的官方的回复如下
Please create a public repo called simonalong/OSSRH-49415 to verify github account ownership.
If you do not own this github account, please read:
http://central.sonatype.org/pages/choosing-your-coordinates.html
如同是我还得创立一个公共的仓库,名字叫OSSRH-49415,去自己的账号中创立一个这样的公共仓库就好了,创立完之后在issue中回复下就好,比方image.png
最后会收到对应的回复,比方image.png整个评论回复如下
image.png
5.生成公钥
mac 进行安装gpg
brew install -v gpg
生成密钥
gps –gen-key
image.png
输入o,就是表示确认,而后两次密码确认image.png
查看公钥
gpg –list-key
image.png
6.发布公钥
主要是将我们的公钥发布给官方,让其能够解析我们本地用私钥加密后的数据
gpg –keyserver hkp://pool.sks-keyservers.net –send-keys 你的公钥
比方
gpg –keyserver hkp://pool.sks-keyservers.net –send-keys 14A4854E9312A84AF051C61494254BDBB854A311
查看能否上传成功
gpg –keyserver hkp://pool.sks-keyservers.net –recv-keys 你的公钥
image.png
7.配置maven
我这里新建一个settings.xml,而后在里面增加对应的账户信息
<servers> <server> <id>oss</id> <username>客户名</username> <password>密码</password> </server></servers>
8.代码中配置代码发布器
<distributionManagement> <snapshotRepository> <id>oss</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> </snapshotRepository> <repository> <id>oss</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository></distributionManagement>
9.上传
这里上传肯定不要点击idea的deploy按钮,由于deploy和maven-gpg-plugin结合的不是很好,那个gpg插件无法运行,肯定要用用户端或者者iterm就可。运行这样运行
mvn clean deploy –settings /Users/zhouzhenyong/.m2/setting_maven_center.xml
其中会提醒输入gpg的密码,输入就可
10.查看
https://oss.sonatype.org/#stagingRepositories我们可以去这里查看,首先登陆,账号是我们注册的客户名和密码,而后点击左侧的“Staging Respositories(暂存仓库)”,而后在右上角输入groupId,即可以搜索我们的这个
image.png假如在这里能够找到,说明已经发布到这里算是成功了,但是还需要工作人员进行审计,需要在我们的Issue中通知一下工作人员就可在下面的评论中,增加这样的一句评论
The component has been successfully released,please confirm
11.关闭释放仓库
这里其实是暂存库,我们发布到这里之后,假如发布成功,则进行关闭最后即可以了,关闭的时候,其中确认框中输入该项目的详情信息,这个是会在界面上展现用于搜索的image.png
关闭后,查看下面,主要是用于审核,假如成功了,则为下面的。image.png这里也遇到了少量问题,具体的问题看下面的问题就可,关闭完成的话,点击release,也就是将当前的这个库释放,并自动发送到中央仓库
image.png
12.回复issue
当我们发布完成之后,我们可以在issue下面回复一条说明自己已经完成了组件的发布,请求确认,比方我的:
Although I have encountered some problems, finaly I have released my staging repo.The component has been successfully released,please confirm, thanks very much
13.查看中央仓库
当那边的工作人员审批完成之后,即可以将这个issue关闭了,一般过十分钟或者者两个小时左右,我们即可以去中央仓库https://search.maven.org/中查看,应该即可以看到我们的这个项目了,对于更加流行的仓库https://mvnrepository.com,可能需要好几个星期之后才会看到,主要是同步慢。我这边是过了一天之后,这边即可以查看了
image.png
14.以后的发布
以后假如发布该项目,则直接maven发布就可,而后close,而后release就可。不用像上面一样创立issue了,假如发布的项目跟该项目group相同,则按照maven发布->close->release就可,假如不同则要开始注册issue了。不过对于每次发布都手动close和release有点麻烦的话,可以使用nexus-staging-maven-plugin这个插件,但是建议第一次不要使用该插件,手动执行是可以填写少量形容的,但是这个插件执行是不会有任何再输入的,而是一次性就执行完,最后等十几分钟就直接发到仓库中心了。
附录:
1.完整的pom参考
pom.xml 中必需包括:name、description、url、licenses、developers、scm 等基本信息,使用了 Maven 的 profile 功能,只有在 release 的时候才创立源码包、文档包、使用 GPG 进行数字签名。
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.github.simonalong</groupId> <artifactId>mikilin</artifactId> <packaging>jar</packaging> <version>1.4.0</version> <name>Mikilin</name> <url> SimonAlong/Mikilin</url> <description>对象属性核对工具</description> <licenses> <license> <name>The Apache Software License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> </license> </licenses> <developers> <developer> <name>zhouzhenyong</name> <email>simonalongs@126.com</email> <roles> <role>developer</role> </roles> </developer> </developers> <scm> <connection>scm:git:git@github.com:SimonAlong/Mikilin.git</connection> <developerConnection>scm:git:git@github.com:SimonAlong/Mikilin.git</developerConnection> <url>git@github.com:SimonAlong/Mikilin.git</url> </scm> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.0</version> <optional>true</optional> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency> <!--spock测试框架--> <dependency> <groupId>org.spockframework</groupId> <artifactId>spock-core</artifactId> <version>1.2-groovy-2.4</version> <scope>test</scope> <exclusions> <exclusion> <artifactId>groovy-all</artifactId> <groupId>org.codehaus.groovy</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.12</version> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>2.4.8</version> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> <!-- Source --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!-- Javadoc --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.10.4</version> <configuration> <show>private</show> <nohelp>true</nohelp> <charset>UTF-8</charset> <encoding>UTF-8</encoding> <docencoding>UTF-8</docencoding> </configuration> <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> <id>sign-artifacts</id> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <distributionManagement> <snapshotRepository> <id>oss</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> </snapshotRepository> <repository> <id>oss</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository> </distributionManagement></project>
pom.xml 中必需包括:name、description、url、licenses、developers、scm 等基本信息,使用了 Maven 的 profile 功能,只有在 release 的时候才创立源码包、文档包、使用 GPG 进行数字签名。
参考:
https://www.songma.com/p/8c3d7fb09bce
https://www.songma.com/p/8c3d7fb09bce
https://www.songma.com/p/d0e43416aaf6
https://www.songma.com/p/d0e43416aaf6
https://www.iteblog.com/archives/1807.html
https://www.iteblog.com/archives/1807.html
https://zhuanlan.zhihu.com/p/41650855
https://zhuanlan.zhihu.com/p/41650855
https://my.oschina.net/u/2335754/blog/476676
https://my.oschina.net/u/2335754/blog/476676
问题:
1.公钥上传不上去
假如遇到上传公钥上传不上去的问题,可以查看这里
2.maven-gpg-plugin问题
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.6:sign (sign-artifacts) on project mikilin: Exit code: 2 -> [Help 1]
最终的起因是不能用idea 自带的那个终端,<br />注意:!!!!!!!!!!!!!不要使用idea自带的终端,真想说一百字的脏话,尝试了好久,各种问题都尝试了,还有就是要在.bashrc中增加如下的一个就可
export GPG_TTY=$(tty)
3.xxx.asc文件找不到
这个asc文件其实是gpg文件生成的,也就是上面maven-gpg-plugin文件是必需要生效才能生成这些文件的<br />[图片上传失败…(image-25c101-1561878176712)]<br />
4.版本上传注意点
第一次不能上传SNAPSHOT版本
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » maven 第一次发布jar到中央仓库