上传自己的包至maven中央仓库
上传自己的包至maven中央仓库 author: Tank
上传JAR包前的准备工作
注册账号
注册地址 此处注册的账号密码是需要记下来的。因为在上传时需要配置settings.xml内
创建工单 (也就是issues)可以参考我的
Project:自己项目名
Issue Type:选择创建新项目
Summary:随意命名
Group Id:唯一标识,这里需要注意,group id必须是自己的。一般是域名反推如我的。com.plumelog
Project URL:项目地址,我用的是官网地址如www.plumelog.com
SCM url:项目管理地址,如:https://gitee.com/frankchenlong/plumelog
发布issues后需要等待官方审核,审核后会回复如下
1
2
3
4
5
6
7
8
9
10
11Do you own the domain plumelog.com? If so, please verify ownership via one of the following methods:
Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-58071 (Fastest)
Setup a redirect to your Github page (if it does not already exist)
If you do not own this domain, please read:
http://central.sonatype.org/pages/choosing-your-coordinates.html
You may also choose a groupId that reflects your project hosting, in this case, something like
Would you like to use a free managed security reporting service (recommended)?
Put https://hackerone.com/central-security-project/reports/new as your project's security issue reporting URL. We'll take care of the rest.
For more details on the Central Security Project, visit https://www.sonatype.com/central-security-project注意事项:
上面填的group id 的反向域名他会问你是不是你所有。如果是需要配置一个txt的解析。最好是自己申请一个域名。可以避免不少坑。当你配置好txt解析后可以截图发给他,他会去验证
当他验证完成后会回复如下:也就是你可以上传你的包了
1 | com.plumelog has been prepared, now user(s) tank can: |
上传jar需要的配置
配置pom.xml
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
<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.plumelog</groupId>
<artifactId>plumelog</artifactId>
<packaging>pom</packaging>
<version>2.1.2</version>
<description>The parent project of plumelog</description>
<url>https://gitee.com/frankchenlong/plumelog</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<name>plumelog</name>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>https://gitee.com/frankchenlong/plumelog</url>
<connection>scm:git:https://gitee.com/frankchenlong/plumelog.git</connection>
<developerConnection>scm:git:https://gitee.com/frankchenlong/plumelog.git</developerConnection>
</scm>
<developers>
<developer>
<name>tank</name>
<email>252720074@qq.com</email>
<url>http://www.plumelog.com</url>
</developer>
</developers>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>-->
<id>ossrh</id>-->
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<!-- 这里的id必须要和全局配置中的release id 一致 -->
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<!--Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.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.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 这里需要写自己的地址,我是直接用的绝对地址,你可以使用环境变量--> <javadocExecutable>/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/bin/javadoc</javadocExecutable>
</configuration>
</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>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>配置settings.xml
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<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<server>
<id>sonatype-nexus-staging</id>
<username>tank</username>
<password>xxxx</password>
</server>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>the_pass_phrase</gpg.passphrase>
</properties>
<repositories>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</settings>
GPG 密钥生成
先下载GPG 下载安装gpg,https://www.gpg4win.org/download.html
执行命令: gpg –gen-key 即可生成密钥 这里就不截图了,过程中需要填写一个密码,记住他,下一步打包上传的时候需要它。打开GPG窗口可以看到如下
点击箭头处,将公钥发送到服务器
上传jar
这个过程可能会有点慢,上传时会有点卡过程中需要填写一个密码 也就是生成gpg时填的密码。
1 | mvn clean deploy 即可将jar上传到https://oss.sonatype.org/ 这是一个临时存入jar 的地方 |
当上传完成后可以至https://oss.sonatype.org/#welcome 查看
点Release即可同步至中央仓库,这中间需要等待一段时间。然后就可以在中央仓库查询到了