我的开源包eweb已经发布到maven中心库了,使用maven配置就可以引入:
<dependency>
<groupId>com.github.chuanzh</groupId>
<artifactId>eweb</artifactId>
<version>1.0.1</version>
</dependency>
下面讲讲如何发布到中心库,查了网上的步骤,都说的比较复制,但其实也很简单,这里分下面几个步骤:
一,Sonatype账号注册&创建一个Issue
二,使用GPG生成秘钥
三,修改项目的maven配置文件
四,上传构件到OSS&发布
看懂了之后其实很好理解,其实就类似于申请接入腾讯,微博的APP应用,
第一步,你得成为一个开发者吧,也就是要注册一个开发者账号,接下来就是要创建一个应用,等待腾讯、微博服务商审核
第二步,审核通过后,腾讯、微博会给你一对秘钥,但maven是要自己生成的,也就是用GPG
第三步,在你的项目中配置密钥和其他配置。
第四部,就是上传你的项目到腾讯、微博的服务平台,然后再等待审核,审核通过,那你就可以在他们的平台使用APP了
下面就从这4个方面说明下。
一,Sonatype账号注册&创建一个Issue
注册地址: Sign up for JIRA
记住你的用户名和密码,之后要用到
创建一个Issue:https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134
填写项目的基本信息:简单描述,详细描述,项目地址
重点说明下:Group Id为你项目的groupid,一般为公司或个人域名,如果你没有,就不要随便写了(他们在审核时会要求你提供一些证明的),写github的项目地址就可以了
好了,现在你就可以静静的等待maven审核了,一般为1~2天
二,使用GPG生成秘钥
首先需要下载GPG软件,Mac下载地址:GPG Suite,Windows用户下载地址:Secure email and file encryption with GnuPG for Windows,我的是Mac,所以具体说说Mac下的生成方式,Window方式请参考这篇博客
Mac下生成很简单,如下几个步骤:
1,新建一个密钥
2,点击右键,将公钥发送至公钥服务器
到此密钥就生成了,记住你的口令,后面要用到
三,修改项目的maven配置文件
1,修改maven的setting配置
<settings>
...
<servers>
<server>
<id>oss</id>
<username>用户名</username>
<password>密码</password>
</server>
</servers>
...
</settings>
用户名和密码就是你注册Sonatype的账号
2,配置项目pom.xml文件
<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.chuanzh</groupId>
<artifactId>eweb</artifactId>
<version>1.0.1</version>
<packaging>jar</packaging>
<name>eweb</name>
<description>轻量web开发框架</description>
<url>https://github.com/chuanzh/eweb</url>
<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>chuan.zhang</name>
<email>zhangchuan0305@gmail.com</email>
</developer>
</developers>
<scm>
<connection>scm:git@github.com:chuanzh/eweb.git</connection>
<developerConnection>scm:git@github.com:chuanzh/eweb.git</developerConnection>
<url>git@github.com:chuanzh/eweb.git</url>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>utf-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<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>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.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.10.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Gpg Signature -->
<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>
pom.xml必须配置的有:name,description,licenses,developers,scm。
snapshotRepository和repository在Issure初审通过后会给你,另外id要和setting.xml中保持一致
四,上传构件到OSS&发布
1,使用下面命令,会提示要求你输入GPG的密钥,就是申请时候填写的,此过程比较慢,需要耐心等待
mvn clean deploy -P release
2,在OSS中发布构件
使用sonatype账号登陆https://oss.sonatype.org ,通过模糊查找,选择Staging Repositories,如下图,该构件的状态此时应该为open,勾选它,点击close按钮,sonatype会先做检验,通过后,就可以点击Release了,如果审核不通过,尝试删掉后重新上传
3,通知sonatype已经发布构建
也就是在Issure中回复,再次等待,也是需要审核1~2天,若审核通过,会回复你如下的信息
等待10分钟,你就可以在maven库中搜索到你的jar包了
若下次修改了本地的代码,只需要重新执行第四步的命令即可







