如何发布jar包到maven中央仓库

自使用maven以来,没少使用maven中央仓库中的各种jar包,方便有效,但是咱们也不能总是只取不予,也应该懂得奉献,当你写好了一个十分好用的jar包,想贡献出去给大家使用的时候,应该怎么做呢?当然是发布到maven的中央仓库了,不过要说这个发布过程,还真是比较复杂,本文就来详细说下如何发布jar包到maven中央仓库。 
开始之前,请注意几个地址: 
1、工单管理:https://issues.sonatype.org/secure/Dashboard.jspa

说明:注册账号、创建和管理issue,Jar包的发布是以解决issue的方式起步的

2、构件仓库:https://oss.sonatype.org/#welcome

说明:算是正式发布前的一个过段仓库,使用maven提交后的jar包先到这个库中

1、创建工单

在上述的工单管理的地址中进行创建,如果没有账号,需要先注册一个,记住用户名密码,后边要配置到setting.xml中。 
Create Issue 填写内容说明: 

===Step 1===
Project:Community Support - Open Source Project Repository Hosting
Issue Type:New Project

===Step 2===
Summary:JAR包名称,如:marathon-client
Group Id:你懂得,不用多说,如com.cloudnil
Project URL:项目站点,如:https://github.com/CloudNil/marathon-client
SCM url:项目源码仓库,如:https://github.com/CloudNil/marathon-client.git

其他内容不用填写,创建Issue后需要等待一小段时间,Sonatype的工作人员审核处理,速度还是很快的,一般一个工作日以内,当Issue的Status变为RESOLVED后,就可以进行下一步操作了,否则,就等待… 

2、配置Maven

在工程的pom.xml文件中,引入Sonatype官方的一个通用配置oss-parent,这样做的好处是很多pom.xml的发布配置不需要自己配置了:

    <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>7</version>
    </parent>

并增加Licenses、SCM、Developers信息:

    <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>
        <tag>master</tag>
        <url>git@github.com:cloudnil/marathon-client.git</url>
        <connection>scm:git:git@github.com:cloudnil/marathon-client.git</connection>
        <developerConnection>scm:git:git@github.com:cloudnil/marathon-client.git</developerConnection>
    </scm>
    <developers>
        <developer>
            <name>cloudnil</name>
            <email>cloudnil@126.com</email>
            <organization>CloudNil</organization>
        </developer>
    </developers>

修改maven配置文件setting.xml,在servers中增加server配置,找不到这个文件的同学请自己去旁边哭会先。

  <servers>
    <server>
      <id>sonatype-nexus-snapshots</id>
      <username>Sonatype 账号</username>
      <password>Sonatype 密码</password>
    </server>
    <server>
      <id>sonatype-nexus-staging</id>
      <username>Sonatype 账号</username>
      <password>Sonatype 密码</password>
    </server>
  </servers>

3、配置gpg-key

如果是使用的windows,可以下载gpg4win,地址:https://www.gpg4win.org/download.html,安装后在命令行中执行 gpg --gen-key生成,过程中需要填写名字、邮箱等,其他步骤可以使用默认值,不过有个叫:Passphase的参数需要记住,这个相当于是是密钥的密码,下一步发布过程中进行签名操作的时候会用到。 

4、Deploy

这步就简单了,就是一套命令:

mvn clean deploy -P sonatype-oss-release -Darguments="gpg.passphrase=密钥密码"

如果使用eclipse的mvn插件发布的话,配置如下: 
 
如果发布成功,就可以到构件仓库中查看了。

5、Release

进入https://oss.sonatype.org/#stagingRepositories查看发布好的构件,点击左侧的Staging Repositories,一般最后一个就是刚刚发布的jar了,此时的构件状态为open。 
打开命令行窗口,查看gpg key并上传到第三方的key验证库:

E:\98_code\workSpace\marathon-client>gpg --list-keys
C:/Users/VF/AppData/Roaming/gnupg/pubring.gpg
---------------------------------------------
pub   2048R/824B4D7A 2016-01-06
uid       [ultimate] cloudnil <cloudnil@126.com>
sub   2048R/7A10AD69 2016-01-06

E:\98_code\workSpace\marathon-client>gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 824B4D7A
gpg: sending key 824B4D7A to hkp server keyserver.ubuntu.com

E:\98_code\workSpace\marathon-client>
回到https://oss.sonatype.org/#stagingRepositories,选中刚才发布的构件,并点击上方的close–>Confirm,在下边的Activity选项卡中查看状态,当状态变成closed后,执行Release–>Confirm,并在下边的Activity选项卡中查看状态,成功后构件自动删除,一小段时间(约1-2个小时)后即可同步到maven的中央仓库。

http://blog.csdn.net/tiger435/article/details/50470316

https://www.iteblog.com/archives/1807.html

SCM Implementation: Git

General Info

Link: http://git-scm.com/

License: GNU General Public License v2

SCM URL

For all URLs below, we use a colon (:) as separator. If you use a colon for one of the variables (e.g. a windows path), then use a pipe (|) as separator. The separator for the port has to be a colon in any case since this part is specified in the git URL specification. See man git-fetch.

scm:git:git://server_name[:port]/path_to_repository
scm:git:http://server_name[:port]/path_to_repository
scm:git:https://server_name[:port]/path_to_repository
scm:git:ssh://server_name[:port]/path_to_repository
scm:git:file://[hostname]/path_to_repository
  • Examples

    scm:git:git://github.com/path_to_repository
    scm:git:http://github.com/path_to_repository
    scm:git:https://github.com/path_to_repository
    scm:git:ssh://github.com/path_to_repository
    scm:git:file://localhost/path_to_repository

Different Fetch and Push URLs

In some cases a different URL has to be used for read and write operations. This can happen if e.g. fetch is performed via the http protocol, but writing to the repository is only possible via ssh. In this case both URLs may be written into the developerConnection tag. The fetch URL has to be prefixed with [fetch=] and the push URL with [push=]

  • Example:

    <developerConnection>scm:git:[fetch=]http://mywebserver.org/path_to_repository[push=]ssh://username@otherserver:8898/~/repopath.git</developerConnection>

Working with branches

Since version 1.3, we assume that the name of the branch in the upstream repo is the same as the name of the current local branch. So whenever you invoke a maven-scm action which has to access the upstream repository, e.g. start a release, you should be on that very branch.

In other words: If no branch is specified manually, every git-fetch, git-pull, git-push, etc will always work on the branch in the upstream repository which has the same branch name as your current local branch

git push pushUrl currentBranch:currentBranch

Provider Configuration

The provider configuration is defined in $user.home/.scm/git-settings.xml.

<git-settings>
  <!-- will had the option --no-verify to the commit command can be helpfull to ignore trailing spaces issues with cygwin and the release plugin -->
  <commitNoVerify>false</commitNoVerify>
</git-settings>

http://maven.apache.org/scm/git.html

 

时间: 2024-08-23 05:00:52

如何发布jar包到maven中央仓库的相关文章

maven deploy 失败-maven 发布jar包到私服失败

问题描述 maven 发布jar包到私服失败 mvn clean deploy source:jar -Dmaven.test.skip=true,无法发布jar包到私服. 解决方案 Maven 发布jar包到远程仓库maven 发布jar包到远程仓库,Maven : 将Jar安装到本地仓库和Jar上传到私服

Maven 中央仓库启用 SSL

为了应对黑客可以向Maven中央仓库上传普通代码库的恶意版本这一问题,Sonatype公司启用了SSL连接以供测试之用.Sonatype公司之所以这样做的目的是为了在经历一个过渡期之后让SSL这一连接模式成为默认的连接方式.Sonatype公司的产品管理副总裁Brian Fox 主动对此事进行了评论,并说明最早提出SSL连接需求的是Sonatype公司的商业客户.他将这一问题之所以持续了这么久的原因归咎于大众的"安全盲点",目前的事实就是从2012年以来,只有12个用户签约了启用SSL

eclipse 导入jar包 和maven依赖关系问题

问题描述 eclipse 导入jar包 和maven依赖关系问题 eclipse已经导入jar包就可以用到里面的内容了,那要maven的依赖关系还用什么用 解决方案 如果导入了,不用maven也可以.不过maven感觉方便一些.

服务器-JAVA 关于发布JAR包后热部署问题

问题描述 JAVA 关于发布JAR包后热部署问题 目前有2台服务器,负载均衡,2台服务器上分别部署了WINDOWS后台服务程序, 修改了JAR包后,可以不重启服务重新加载吗?万分感谢! 解决方案 方法: 1. 先了解类加载器,编写自定义类加载器 2. OSGI技术,已经有很规范的技术实现了 解决方案二: 修改tomcat的 server.xml 设置 reloadable="true" ,重启后即可!

Maven 中央仓库地址

Maven 中央仓库地址: 1. http://www.sonatype.org/nexus/ 2. http://mvnrepository.com/ (本人推荐仓库) 3. http://repo1.maven.org/maven2

将jar发布到maven中央仓库小记

dexcoder-assistant发布也经历几个版本了,很多人反映使用不太方便,需要将源码下来后本地编译安装一下,如果能直接使用就好了. osc提供了第三方的maven库,但终究没有官方的maven库来得方便. 本文是将dexcoder-assistant发布到Maven中央库的记录. 注册一个 Sonatype 用户 注册地址:https://issues.sonatype.org/secure/Signup!default.jspa 使用了JIRA来管理流程,记住用户名和密码,后面会用到.

请问如何才能把maven中央仓库所有的jar包都下载下来呢?

问题描述 用maven开发,环境是局域网,本来以为用那个nexus可以把所有jar包下载下来搭建本地仓库,貌似不是那么回事,咋整啊...ps.找遍所有马甲终于发现了个可用分大于20的-- 解决方案 解决方案二:你有maven依赖的话,会自行下载.当然,同一个版本的jar只下一次解决方案三:是局域网不?解决方案四:引用1楼defonds的回复: 你有maven依赖的话,会自行下载.当然,同一个版本的jar只下一次 maven所有jar包的pom这个能找到吗?解决方案五:所有?有本地库的概念呀

解决maven仓库有jar包但是maven程序无法下载仓库jar包

  话说,这个问题困扰了我两个多月了已经~~~   后来发现不知道被谁动了,把我的仓库没有放到仓库组里面~~~   用admin登录进去,默认密码是admin123,然后看截图操作吧.   (记得删除你本地报错说**jar包的路径,去自己的.m2 文件夹下把 xxx.lastUpdated文件全部删掉.) 解决Maven架设Nexus私服no dependency information availa问题 解决Maven架设Nexus私服The POM for .... is missing,

怎样将jar包添加到maven仓库里面??

问题描述 怎样将jar包添加到maven仓库里面?? 现有一个maven工程 ,,我现在需要一个第三方的依赖jar 以前没有接触过 maven ,我现在想把这个jar放到maven的库里 , 用pom.xml这种方式加项目 ,,而不是建一个lib文件夹放jar文件,,哪位使,,用过maven的大神 教我一下! 万分感谢! 最好能加下我QQ : 80818647 谢了 解决方案 Maven 安装 JAR 包的命令是: mvn install:install-file -Dfile=jar包的位置