打开地址:Maven Central (sonatype.com)
参考上图,然后进入下一个页面
注册一个账户或者点三方登录注册也可行,目前支持
这里以Sign up 为例:
填写三个信息即可,然后邮箱验证下。就可以使用账户了。
什么是命名空间(Namespace),就是你上传的jar包的groupId,参考
命名空间包含公共托管代码平台空间和私有域名,公共托管平台参考
更多命名空间使用细节,参考:注册 Namespace - 文档 (sonatype.org)
有自己域名则填写域名然后添加对应dns记录完成认证即可
这里的验证key就是需要你添加的txt记录,通过点击Verifiy Namesspace 按钮可以查看详情
添加txt简单来说就是:
在你的域名(如你填写的:com.example)添加一条txt记录
主机记录 :@ (@代表主域名,如果是com.example.demo,则这里填写demo即可,一般认证顶级子级都能用)
记录类型 :txt
记录值 :q7***(验证key)
提示:验证完毕后即可删除该txt记录
CMD:
nslookup -type=TXT yourdomain.com
Powershell:
Resolve-DnsName yourdomain.com -Type TXT
$ host -t txt yourdomain.com
yourdomain.com descriptive text "OSSRH-XXYYZZ"
or
dig -t txt yourdomain.com
dig -t txt yourdomain.com
提示:如果一直显示Verification Pending 则手动取消再验证一下
然后再点击Verifiy Namespace,然后通过View History 还能看到历史验证结果。验证通过后如下:
完成Namespace 校验后就可以使用该命名空间进行上传jar包了。
前置条件
打开maven的配置文件setting.xml(一般在用户主目录的.m2/setting.xml),编辑servers
节点,添加一个server
...其他忽略...
<settings>
<servers>
<server>
<id>central</id>
<username><!-- your token username --></username>
<password><!-- your token password --></password>
</server>
</servers>
</settings>
...其他忽略...
配置的username和password来源
提示:重新注册后需要把之前的替换掉。
注意:1分钟后该窗口自动关闭且不在显示。
项目配置:
新版配置:
<profiles>
<!--maven center repository-->
<profile>
<id>oss-release</id>
<build>
<plugins>
<!-- 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>
<!-- 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>
<!-- GPG -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- sonatype release plugin autoRelease -->
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.5.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>maven-center</publishingServerId>
<autoPublish>true</autoPublish>
<waitUntil>published</waitUntil>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
新版对比老版本的插件区别
<profiles>
<!--maven center repository-->
<profile>
<id>oss-release</id>
<build>
<plugins>
<!-- 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>
<!-- 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>
<!-- GPG -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- sonatype release plugin autoRelease -->
<!-- <plugin>-->
<!-- <groupId>org.sonatype.plugins</groupId>-->
<!-- <artifactId>nexus-staging-maven-plugin</artifactId>-->
<!-- <version>1.6.7</version>-->
<!-- <extensions>true</extensions>-->
<!-- <configuration>-->
<!-- <serverId>maven-center</serverId>-->
<!-- <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>-->
<!-- <autoReleaseAfterClose>true</autoReleaseAfterClose>-->
<!-- </configuration>-->
<!-- </plugin>-->
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.5.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>maven-center</publishingServerId>
<autoPublish>true</autoPublish>
<waitUntil>published</waitUntil>
</configuration>
</plugin>
</plugins>
</build>
<!-- <distributionManagement>-->
<!-- <!–oss–>-->
<!-- <snapshotRepository>-->
<!-- <id>maven-center</id>-->
<!-- <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>-->
<!-- </snapshotRepository>-->
<!-- <repository>-->
<!-- <id>maven-center</id>-->
<!-- <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>-->
<!-- </repository>-->
<!-- </distributionManagement>-->
</profile>
</profiles>
注意:oss配置部分,id配置上面server里面配置的id,另外插件里面需要配置id
其他信息 开发者信息,许可信息,仓库信息等。
然后通过maven进行打包上传
deploy会让你输入密码(GPG加密的)
点击Namespace 旁边的Deployments,然后点击Publish Compoment
接下来发生 了一个错误
导致这个错误的原因目前未知。
试了几次手动还是有点问题,使用下面插件直接编译上传
https://www.leftso.com/article/2407291619084773.html