第一次发布jar包到Maven中央仓库
在网上找了不少资料
总体流程如下:
申请账号并创建issue
- 申请账号略
- 创建issue
- 等待工作人员处理issue,并回复
安装gpg,生成秘钥并发布
- 安装过程略(这里使用的是windows版)
- 生成秘钥
gpg --gen-key
根据提示输入真实姓名,邮箱,并输入两次密码,这里生成的密码 用于后面的发布
- 生成秘钥后可用
gpg --list-keys
查看本地秘钥,一长串的字母就是公钥ID - 将公钥发布到秘钥服务器
- 发布到那个服务器不唯一,在网上查到的资料是用以下服务器,如果没发布公钥到服务器上,发布jar会报错找不到公钥ID,并提示发布到哪些服务器上
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 公钥ID
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 公钥ID
查询公钥是否发布成功
Maven配置
- pom.xml配置包括
name
,description
,url
,licenses
,developers
,scm
等1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<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>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<groupId>io.github.andersonfeng</groupId>
<artifactId>com.github.andersonfeng.mybatis-generator-plugins</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<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>
<url>https://github.com/Andersonfeng/mybatis-generator-plugins</url>
<connection>https://github.com/Andersonfeng/mybatis-generator-plugins.git</connection>
<developerConnection>https://github.com/Andersonfeng</developerConnection>
</scm>
<developers>
<developer>
<name>andersonfeng</name>
<email>262643608@qq.com</email>
<url>https://andersonfeng.github.io/</url>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype-nexus-staging</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>disable-javadoc-doclint</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<!-- java8版本导致javadoc打包编译失败时候,添加-->
<properties>
<javadoc.opts>-Xdoclint:none</javadoc.opts>
</properties>
</profile>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype-nexus-staging</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<!-- java8版本导致javadoc打包编译失败时候,添加-->
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> setting.xml配置
1
2
3
4
5
6
7
8
9
10
11<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>- 发布
mvn clean install deploy -P release -Dgpg.passphrase=生成秘钥时候的密码
操作Nexus
- 进入Nexus的Build Promotion-Staging Repositories
- 根据groupId搜获刚刚的构建
- 选择构建并点击close
- 等待几分钟构建的状态变为close后点击release
- 回复issue(大概让工作人员知道你已经操作成功了,不知道是否必要,不过出于礼貌也应该告知一下)
- 随后工作人员会给答复
等待
- 第二天发现项目已经发布到maven中央仓库了