Maven 地方仓库提交Jar包全程指南
本文记录一下将jar上传到maven地方仓库的全过程,文中我的项目依靠在github上,应用的是mac环境 (对于maven、jdk的环境配置不属于本文内容)
<!-- more -->
1. sonatype账号申请
首先咱们须要申请一个账号,地址为: https://issues.sonatype.org/secure/Signup!default.jspa
请记住这个账号的用户名 + 明码,在后续的maven的setting.xml
配置文件中须要用到
账号申请结束之后,点击新建
按钮(如果是因为的话,就是create
),提交一个issue
- 我的项目:抉择
Community Support - Open Source Project Repository Hosting (OSSRH)
- 问题类型:抉择
New Project
- 概要:我的项目阐明
- 形容:我的项目阐明
- GroupId: 请留神,对于github我的项目而言,前缀都是
com.github
,前面跟着的是你的账号名,比方我的账号是liuyueyi
,所以我的groupId是com.github.liuyueyi
,如果不满足这个规定将无奈通过后续的审核 Project URL
: 我的项目地址,填对应的github连贯 https://github.com/liuyueyi/quick-chinese-transferSCM URL
: 和下面的基本一致,只是多了一个.git
基本上须要配置的货色如下图,最初点击新建即可
下面提交之后,期待审核即可
2. GPG装置
在后续的上传jar包时,须要利用gpg进行签名,上面介绍一下mac的装置流程
举荐用法
macos装置能够借助homebrew来实现
brew install gpg
备选计划
然而我的mac零碎比拟老,应用下面的形式装置失败,间接抛了异样,依据搜寻后果来看,不降级零碎貌似没有什么好的解决办法
上面是采纳安装包的形式,原则上倡议到官网去下载安装包,仍然是因为版本问题,最新的我也装置不上,所以找了一个历史的下载网址,(不保障这个网站上的安装包的安全性。尽管我本人用的也是它)
如有须要,能够跳转: https://sourceforge.net/p/gpgosx/docu/Download/
我抉择的是2.2.12
版本,装置结束之后,能够查看一下外面的readme
文件,查看具体的装置门路
比方在我的电脑上装置门路为: /usr/local/gnupg-2.2/bin
,为了方便使用,能够设置一下环境
vim ~/.bash_profile# 增加新的path门路PATH=$PATH:/usr/local/gnupg-2.2/binsource ~/.bash_profile
密钥生成及公布
装置结束之后,设置咱们本人的密钥
# 生成密钥对# 输出用户名 + 邮箱,请记住这个明码,前面上传jar包的时候会用到gpg --gen-key
查看本地密钥
# 生成结束之后,查看本地密钥gpg --list-keys
上图中勾住的就是咱们的公钥id,接下来将公钥id上传到密钥服务器
## 上传公钥gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 公钥ID## 查看公钥上传状况gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 公钥ID
3. maven配置
接下来,咱们须要设置一下咱们的maven配置文件setting.xml
,将咱们的用户信息填写进去
vim ~/.m2/setting.xml
增加第一步中申请的账号信息,(用户名+明码就是第一步申请的账号密码)
# 增加账号信息<servers> <server> <id>ossrh</id> <username>user</username> <password>password</password> </server></servers>
4. 我的项目配置
后面的步骤属于大的环境相干,接下来就须要在咱们的理论我的项目中,配置必要的信息了,这里以https://github.com/liuyueyi/quick-chinese-transfer的配置为实例进行阐明
<?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.liuyueyi</groupId> <artifactId>quick-chinese-transfer</artifactId> <packaging>pom</packaging> <version>0.1</version> <modules> <module>transfer-core</module> </modules> <name>quick-chinese-transfer</name> <description> A Java library supporting conversion between Simplified-Chinese, Traditional-Chinese </description> <url>https://github.com/liuyueyi/quick-chinese-transfer</url> <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> <issueManagement> <system>github</system> <url>https://github.com/liuyueyi/quick-chinese-transfer/issues</url> </issueManagement> <scm> <connection>scm:git:https://github.com/liuyueyi/quick-chinese-transfer.git</connection> <developerConnection>scm:git:https://github.com/liuyueyi/quick-chinese-transfer.git</developerConnection> <url>https://github.com/liuyueyi/quick-chinese-transfer</url> </scm> <developers> <developer> <name>YiHui</name> <email>bangzewu@126.com</email> <url>http://blog.hhui.top</url> </developer> </developers> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <configuration> <mavenExecutorId>forked-path</mavenExecutorId> <useReleaseProfile>false</useReleaseProfile> <arguments>-Psonatype-oss-release</arguments> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.1.0</version> <inherited>true</inherited> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> <configuration> <excludeResources>true</excludeResources> <useDefaultExcludes>true</useDefaultExcludes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>3.0.0</version> <inherited>true</inherited> <executions> <execution> <id>bundle-sources</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> <configuration> <maxmemory>1024</maxmemory> <encoding>UTF-8</encoding> <show>protected</show> <notree>true</notree> <!-- Avoid running into Java 8's very restrictive doclint issues --> <failOnError>false</failOnError> <doclint>none</doclint> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.7</version> <configuration> <formats> <format>html</format> <format>xml</format> </formats> <check/> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.1.0</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> </plugin> </plugins> </build> <distributionManagement> <repository> <id>ossrh</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository> <snapshotRepository> <id>ossrh</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement> <profiles> <profile> <id>release</id> <build> <plugins> <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> </profile> </profiles></project>
下面是一个残缺的配置信息,其中,十分外围的几个点
groupId
: 请留神与申请的保持一致plugins
: 咱们上传的jar包,须要蕴含doc和源码,所以maven-source-plugin
+maven-javadoc-plugin
必不可少maven-gpg-plugin
: 签名的插件,必要
在我的理论我的项目开发过程中,这里遇到了一个问题,maven-gpg-plugin
下载不下来始终标红,如果遇到这种问题,能够定向下载
mvn dependency:get -DrepoUrl=http://repo.maven.apache.org/maven2/ -Dartifact=org.apache.maven.plugins:maven-gpg-plugin:1.6
除此之外,还能够通过idea设置 -> maven -> Repositories
更新依赖
下面这个配置结束之后,就是打包上传,间接应用以下命令即可
mvn clean deploy -DskipTests=true -P release
这个命令执行过程中,会弹出一个输出gpg明码的弹窗,输出咱们第二步中生成gpg密钥时,填写的明码即可
jar包上传完毕之后,就能够在https://oss.sonatype.org/看到了
留神
当咱们第一步提交的issues审核之后,会有一个邮件告诉你,能够公布对应的jar包了,也能够在issues看到上面的回复,个别有上面两步
- 提醒你在github上创立一个权限验证的空的仓库
- 创立结束之后,扭转issue状态
- 提醒你能够上传jar包了
- 接着执行下面的jar包公布
5. jar包公布
接下来登录 https://oss.sonatype.org/#stagingRepositories 治理咱们上传的jar包
- 点击
Staging Repositories
- 选中咱们须要公布的jar
- 点击close
close点击结束之后,如果一切正常,那么期待一段时间之后,就能够发现release按钮能够点击了,而后点击release公布即可
如果一切顺利,咱们会收到一个邮件,通知咱们公布胜利,筹备同步jar包了
而后等十来分钟,就能够间接依赖导入jar包了
<dependency> <groupId>com.github.liuyueyi</groupId> <artifactId>quick-transfer-core</artifactId> <version>0.1</version></dependency>
留神
对于下面这个公布,有可能没有那么顺利,比方我之前遇到了几个问题,点击选中包的Activites
能够查看失败的起因
下面几个问题的起因次要在于我的项目的pom配置有问题,导致上传的包没有签名,没有source
, java-doc
其次还遇到过一次说是gpg密钥没有找到的问题,这个有可能是因为咱们上传的密钥还没有同步过来,有提早,再试一次就能够了
5. 小结
尽管网上挺多这种教程,然而在理论的操作中,总会遇到一些他人没有遇到的问题,当然如果没有遇到问题,那当然是最侥幸的事件了;本文次要是为了记录jar包上传的地方仓库的全过程,做一个演绎小结,也不便后续的查阅,当然如果对其余的小伙伴能有所帮忙也是不错的
在写本文的时候,曾经能够在地方仓库搜寻到上传的jar包了
参考文档
- 将我的项目公布到 maven 地方仓库踩过的坑
- 如何提交我的项目到Maven地方仓库(图文详解)
II. 其余
1. 一灰灰Blog: https://liuyueyi.github.io/he...
一灰灰的集体博客,记录所有学习和工作中的博文,欢送大家前去逛逛
2. 申明
尽信书则不如,以上内容,纯属一家之言,因集体能力无限,不免有疏漏和谬误之处,如发现bug或者有更好的倡议,欢送批评指正,不吝感谢
- 微博地址: 小灰灰Blog
- 微信公众号:一灰灰blog