中央仓库 Open Source Software Repository Hosting 简称 OSSRH
实现目标:将自定义项目上传至maven中央仓库,其他人只需引入maven坐标即可直接使用
上传步骤:亲测有效
Jira Software
步骤不多说,密码记住,之后要频繁用到
邮件回复内容一般为:
内容有两个:
To continue the registration process, please follow these steps:
# Create a temporary, public repository called https://github.com/xxx/OSSRH-91364 to verify github account ownership.
# *Edit this ticket* and set Status to Open.
If you do not own this github account, you must define a new groupId.
More info: https://central.sonatype.org/publish/requirements/coordinates/ and https://central.sonatype.org/faq/verify-ownership/
官方验证完后会邮件回复你,通知你的中央仓库已激活,分别上传你项目的SNAPSHOT和release版本至指定地址
Congratulations! Welcome to the Central Repository!
io.github.xxx has been prepared, now user(s) xxxx.com can:
Publish snapshot and release artifacts to *s01.oss.sonatype.org*
Have a look at this section of our official guide for deployment instructions:
https://central.sonatype.org/publish/publish-guide/#deployment
Depending on your build configuration, your first component(s) might be released automatically after a successful deployment.
If that happens, you will see a comment on this ticket confirming that your artifact has synced to Maven Central.
If you do not see this comment within an hour or two, you can follow the steps in this section of our guide:
https://central.sonatype.org/publish/release/
参考文档地址:OSSRH Guide - The Central Repository Documentation
流程:下载GPG签名工具->生成秘钥->配置settings.xml->配置pom.xml->上传
下载地址:https://www.gnupg.org/download/index.html
生成:
gpg --gen-key
Real name: 名字(英文)
Email address: 邮箱(自己的邮箱)
You selected this USER-ID:
"xxx[[email protected]](mailto:[email protected])"
Change (N)ame, (E)mail, or (O)kay/(Q)uit? o
之后往下,会让你输入用户名和邮箱,还有一个Passphase(输入两次,务必牢记,建议先找个地方记下来,后续要用到)
查看公钥
gpg --list-keys
查询结果:
--------------------------------------------------
pub rsa2048 2021-02-02 [SC] [expires: 2023-02-02]
453294371E0A38D70216B1E527EDC1D957E41325
uid [ultimate] xxxxx <[email protected]>
sub rsa2048 2021-02-02 [E] [expires: 2023-02-02]
pub就是公钥:453294371E0A38D70216B1E527EDC1D957E41325
发布公钥:
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 453294371E0A38D70216B1E527EDC1D957E41325
查询发布公钥是否成功
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 453294371E0A38D70216B1E527EDC1D957E41325
成功的话会有如下结果
gpg: key 27EDC1D952E45891: "xxxxxx " not changed
gpg: Total number processed: 1
gpg: unchanged: 1
配置本地maven的配置文件
<servers>
<server>
<id>ossrhid>
<username>[email protected](SonaType账号)username>
<password>填你注册SonaType时填写的密码password>
server>
servers>
<profiles>
<profile>
<id>ossrhid>
<activation>
<activeByDefault>trueactiveByDefault>
activation>
<properties>
<gpg.executable>/usr/local/MacGPG2/bin/gpggpg.executable>
<gpg.passphrase>填写你生成秘钥时输入的密码gpg.passphrase>
<gpg.homedir>C:/Users/laohan/.gnupggpg.homedir>
properties>
profile>
profiles>
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<github.global.server>githubgithub.global.server>
properties>
<dependencies>
dependencies>
<groupId>io.github.lindaifenggroupId>
<artifactId>auto-sensitiveartifactId>
<version>1.0.0-SNAPSHOTversion>
<name>auto-sensitivename>
<description>data sensitivedescription>
<url>https://github.com/lindaifeng/auto-sensitiveurl>
<licenses>
<license>
<name>The Apache Software License, Version 2.0name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txturl>
license>
licenses>
<developers>
<developer>
<id>qingfengid>
<name>qingfengname>
<email>[email protected]email>
<roles>
<role>Project Managerrole>
<role>Architectrole>
roles>
<timezone>+8timezone>
developer>
developers>
<scm>
<connection>https://github.com/lindaifeng/auto-sensitive.gitconnection>
<developerConnection>scm:git:ssh://[email protected]:lindaifeng/auto-sensitive.gitdeveloperConnection>
<url>https://github.com/lindaifeng/auto-sensitiveurl>
scm>
<profiles>
<profile>
<id>ossrhid>
<activation>
<activeByDefault>trueactiveByDefault>
activation>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.pluginsgroupId>
<artifactId>nexus-staging-maven-pluginartifactId>
<version>1.6.7version>
<extensions>trueextensions>
<configuration>
<serverId>ossrhserverId>
<nexusUrl>https://s01.oss.sonatype.org/nexusUrl>
<autoReleaseAfterClose>trueautoReleaseAfterClose>
configuration>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-source-pluginartifactId>
<version>2.2.1version>
<executions>
<execution>
<id>attach-sourcesid>
<goals>
<goal>jar-no-forkgoal>
goals>
execution>
executions>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-javadoc-pluginartifactId>
<version>2.9.1version>
<executions>
<execution>
<id>attach-javadocsid>
<goals>
<goal>jargoal>
goals>
<configuration>
<additionalparam>-Xdoclint:noneadditionalparam>
<javadocExecutable>/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/bin/javadocjavadocExecutable>
configuration>
execution>
executions>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-gpg-pluginartifactId>
<version>1.5version>
<executions>
<execution>
<id>sign-artifactsid>
<phase>verifyphase>
<goals>
<goal>signgoal>
goals>
execution>
executions>
plugin>
plugins>
build>
<distributionManagement>
<snapshotRepository>
<id>ossrhid>
<url>https://s01.oss.sonatype.org/content/repositories/snapshotsurl>
snapshotRepository>
<repository>
<id>ossrhid>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/url>
repository>
distributionManagement>
profile>
profiles>
尝试maven打包 clean package
build success则可以上传,有报错则根据错误信息解决错误
通过maven打包clean,deploy 弹出对话框输入生成gpg时填写的密码,success则上传成功。
浏览器访问Nexus Repository Manager,登录查看你的maven项目
快照仓库查看:https://s01.oss.sonatype.org/content/repositories/snapshots
流程和上传SNAPSHOT步骤一致,下面仅说明差异点:
保持SNAPSHOT原样,修改如下内容即可:
<id>releaseid>
<version>1.0.0version>
<id>releaseid>
<plugin>
<groupId>org.sonatype.pluginsgroupId>
<artifactId>nexus-staging-maven-pluginartifactId>
<version>1.6.7version>
<extensions>trueextensions>
<configuration>
<serverId>ossrhserverId>
<nexusUrl>https://s01.oss.sonatype.org/nexusUrl>
<autoReleaseAfterClose>trueautoReleaseAfterClose>
configuration>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-release-pluginartifactId>
<version>2.5.3version>
<configuration>
<autoVersionSubmodules>trueautoVersionSubmodules>
<useReleaseProfile>falseuseReleaseProfile>
<releaseProfiles>releasereleaseProfiles>
<goals>deploygoals>
configuration>
plugin>
上面执行完成之后,登陆nexus:https://s01.oss.sonatype.org/#stagingRepositories,登上jira账号之后就能看到我们刚刚发布的内容
选中后点击上方的Close,他会检测你的jar包是否存在问题,如果存在问题,点击下方的Activity即可查看具体的问题或者发送邮件给你了,主要影响release的问题大部分都是打包时漏了一些东西,照着问题修复即可。
(轻微问题不修复也可以release)
检测完成后上方的release就会变成可点击的状态,点击release后,你会收到一份邮件:
大致内容为你的稳定版仓库已激活,大约30分钟后你能在中央仓库搜索到依赖
Central sync is activated for io.github.lindaifeng. After you successfully release, your component will be available to the public on Central https://repo1.maven.org/maven2/, typically within 30 minutes, though updates to https://search.maven.org can take up to four hours.
最后你就可以通过maven坐标直接引用你的项目依赖了
Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.
解决方案:需要指定javadoc路径
<!--生成API文档插件-->
<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>
<configuration>
<javadocExecutable>/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/bin/javadoc</javadocExecutable>
</configuration>
</execution>
</executions>
</plugin>
报错File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
解决方案:指定项目编码
在pom.xml文件中加入以下配置
UTF-8
错误: 未知标记:@ Author
解决方案:配置非标准javadoc注释
-Xdoclint:none
提示403:Received status code 403 from server: Forbidden
可能是因为group id不正确
修改域名为申请Maven 时填写的域名。
提示400:Received status code 400 from server: Bad Request
可能是想要上传的版本号在Maven仓库中已存在了