欢迎来交流 vue前端业务框架
1 注册maven(oss)账号
注册地址: https://issues.sonatype.org/secure/Signup!default.jspa

注册成功后登陆到首页
2 创建一个Issue


Project: 项目类型,一般为community。
Issue Type: 问题类型, 新的项目为new project。
Summary:项目名称。
Description:项目描述。
Group Id:对应pom.xml里的group id。如果你有个人或企业的域名,可以为公司的域名,审核时候需要验证当前域名为本人所有,如果没有可以写github对应的个人地址(如:com.github.potenstop)
Project URL: 项目的地址。
SCM url:项目对应的下载地址。
其他保持默认。填写完成后就可以create了。
写的为个人的域名,第一次提交时候需要验证域名, 审核时间大概一两天就可以了。

3 pgp生产秘钥key
下载地址: https://www.gpg4win.org

可以选择捐赠。
新建秘钥

输入名称和邮件

输入passphrase 尽量复杂些

生产完成 保存指纹

生产证书

选中证书->右键->在服务器上发布,发布完成之后通过指纹(6F96BECCD34E3D92417EE4B820B02DCDB0195509)就可以查询到了。

在服务器发布的证书可以在任意一台pc上进行下载。
5 配置settings.xml
使用idea的话settings.xml需要配置maven(安装目录)

找到D:/install/IntelliJ IDEA 2018.1.5/plugins/maven/lib/maven3对应的config目录下的settings.xml,在services节点下增加一个service节点
<server>
<id>oss</id>
<username>maven_username</username>
<password>maven_password</password>
</server>
4 配置pom.xml

name: 项目名称。
description: 项目描述。
url: 项目地址
licenses: 开源协议。
developers: 开发者列表。
scm: 项目的git地址相关。
profiles: 配置不同的环境。比如开发环境 测试环境 发布环境。
groupId: 定义当前maven项目隶属的实际项目。
artifactId: 该元素定义实际项目中的一个Maven项目(模块).
version: 版本号, 带SNAPSHOT为快照版本,否则为 release 版本。
build: 插件。需要加上maven-source-plugin、maven-javadoc-plugin、maven-gpg-plugin三个插件
dependencies: 依赖的模块。
pom.xml 完整配置
<?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>
<name>jnet</name>
<description>base on netty service and client</description>
<url>http://www.potens.top</url>
<licenses>
<license>
<name>The MIT License</name>
<url>http://opensource.org/licenses/MIT</url>
</license>
</licenses>
<developers>
<developer>
<name>potenstop</name>
<email>potenstop@163.com</email>
</developer>
</developers>
<scm>
<connection>scm:git:git@github.com:potenstop/jnet.git</connection>
<developerConnection>scm:git:git@github.com:potenstop/jnet.git</developerConnection>
<url>git@github.com:potenstop/jnet.git</url>
</scm>
<profiles>
<profile>
<!-- 本地开发环境 -->
<id>dev</id>
<properties>
<profiles.active>dev</profiles.active>
</properties>
<activation>
<!-- 设置默认激活这个配置 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!--打包环境-->
<id>release</id>
<properties>
<profiles.active>release</profiles.active>
</properties>
<!--定义snapshots库和releases库的nexus地址-->
<distributionManagement>
<snapshotRepository>
<!--oss需要对应到settings.xml下的service的id-->
<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>
</profile>
<profile>
<!-- 测试环境 -->
<id>beta</id>
<properties>
<profiles.active>beta</profiles.active>
</properties>
</profile>
</profiles>
<groupId>top.potens.jnet</groupId>
<artifactId>jnet</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<!--编译插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!--生产源码文件插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</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.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.5</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.24.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-core -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
5 发布SNAPSHOT版本

1 版本需要带SNAPSHOT
2 profiles为release
3 运行deploy, 没有报错就是上传成功。
...
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/top/potens/jnet/jnet/1.0-SNAPSHOT/jnet-1.0-20180714.141402-1-sources.jar.asc (499 B at 1.2 KB/sec)
Uploading: https://oss.sonatype.org/content/repositories/snapshots/top/potens/jnet/jnet/1.0-SNAPSHOT/maven-metadata.xml
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/top/potens/jnet/jnet/1.0-SNAPSHOT/maven-metadata.xml (2 KB at 1.5 KB/sec)
Uploading: https://oss.sonatype.org/content/repositories/snapshots/top/potens/jnet/jnet/1.0-SNAPSHOT/jnet-1.0-20180714.141402-1-javadoc.jar.asc
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/top/potens/jnet/jnet/1.0-SNAPSHOT/jnet-1.0-20180714.141402-1-javadoc.jar.asc (499 B at 1.2 KB/sec)
Uploading: https://oss.sonatype.org/content/repositories/snapshots/top/potens/jnet/jnet/1.0-SNAPSHOT/maven-metadata.xml
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/top/potens/jnet/jnet/1.0-SNAPSHOT/maven-metadata.xml (2 KB at 1.1 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 52.229 s
[INFO] Finished at: 2018-07-14T22:14:28+08:00
[INFO] Final Memory: 25M/297M
[INFO] ------------------------------------------------------------------------
6 在oss查看快照
地址: https://oss.sonatype.org
可以查看快照的相关信息

7 发布和查看release版本
只需要去掉版本号的SNAPSHOT,在重新执行deploy。
需要登录才可以看到, 用户名和密码和注册maven一致。

8 使用SNAPSHOT版本和release版本
新建top.potens.test项目,pom.xml增加下面配置
<repositories>
<repository>
<id>oss-snapshot</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<repository>
<id>oss-release </id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>top.potens.jnet</groupId>
<artifactId>jnet</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
9 正式同步到Maven中央库
在Sonatype的管理员将上传的项目正式同步到Maven中央库之前,项目会存在于一个中间状态的仓库中(Staging Repository),起始状态为open,我们需要将它变为close。

切换到close后,就能够正式release这个项目,切换方法同close一样,点击release按钮即可。

release成功可以查到release版本和snapsho版本

如果是第一次发布,需要在release成功后再之前的issue添加评论,告知该项目预计release成功。如下图。

10 错误
1 没有找到pgp的key
解决: 打开kleopatra 插件或导入证书
gpg: no default secret key: No secret key
gpg: signing failed: No secret key
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.061 s
[INFO] Finished at: 2018-07-14T22:07:50+08:00
[INFO] Final Memory: 19M/254M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.5:sign (default) on project jnet: Exit code: 2 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
2 使用maven发版之后git push 为403
解决: 删除原有的http配置方式clone的项目,改用ssh重新clone新项目,或者修改.git/conf文件为ssh配置
error: The requested URL returned error: 403 Forbidden while accessing