maven 上传jar到中央库 2024最新方案

教程分享 > Java教程 (509) 2024-07-30 09:16:33

注册maven中央库账户

打开地址:Maven Central (sonatype.com) 

maven 上传jar到中央库 2024最新方案_图示-e324284e00e74918b5de193fca2bccfe.png

参考上图,然后进入下一个页面

maven 上传jar到中央库 2024最新方案_图示-96109d52b7eb40b6a6b64ab8d000ffb1.png

注册一个账户或者点三方登录注册也可行,目前支持

  • 谷歌账户
  • GitHub账户

这里以Sign up 为例:

maven 上传jar到中央库 2024最新方案_图示-7ae915612e0449e9b620e638bd2afd7e.png

填写三个信息即可,然后邮箱验证下。就可以使用账户了。

 

Namespaces (命名空间添加)

 

什么是命名空间(Namespace),就是你上传的jar包的groupId,参考

maven 上传jar到中央库 2024最新方案_图示-6e84736d60314be08ed0cefd0b05f949.png

命名空间包含公共托管代码平台空间和私有域名,公共托管平台参考

maven 上传jar到中央库 2024最新方案_图示-b1b22914f4c34659aae11a84cb342587.png

更多命名空间使用细节,参考:注册 Namespace - 文档 (sonatype.org)

 

私有域名空间添加

有自己域名则填写域名然后添加对应dns记录完成认证即可

maven 上传jar到中央库 2024最新方案_图示-82cc735ef8fd45c1857471397cf5356e.png
默认没有,点击新增
maven 上传jar到中央库 2024最新方案_图示-a17185d110bd49a4b7515e82fef2204b.png
弹出页面输入你的域名即可

 

maven 上传jar到中央库 2024最新方案_图示-d05b82a3619549bd8b2f17e106d55cf8.png
添加后默认未认证

这里的验证key就是需要你添加的txt记录,通过点击Verifiy Namesspace 按钮可以查看详情

 

添加txt简单来说就是:

在你的域名(如你填写的:com.example)添加一条txt记录

主机记录 :@ (@代表主域名,如果是com.example.demo,则这里填写demo即可,一般认证顶级子级都能用

记录类型 :txt

记录值 :q7***(验证key)

提示:验证完毕后即可删除该txt记录

 

maven 上传jar到中央库 2024最新方案_图示-2c6b26391ed5429fb5835208839236e4.png
特别注意,这里的Confirm最好是等txt生效后点击,不然后面要取消再点一次。

 

如何判断txt记录生效

Windows

CMD:

nslookup -type=TXT yourdomain.com

Powershell:

Resolve-DnsName yourdomain.com -Type TXT

Linux

$ host -t txt yourdomain.com
yourdomain.com descriptive text "OSSRH-XXYYZZ"

or

dig -t txt yourdomain.com

macOS

dig -t txt yourdomain.com

 

maven 上传jar到中央库 2024最新方案_图示-50e64e4ccc3449a18af86911c2a1bdb3.png
提示验证中,等待解析生效即可

提示:如果一直显示Verification Pending 则手动取消再验证一下

maven 上传jar到中央库 2024最新方案_图示-ffe48681f7054ae99f2d72f17a5a7fb6.png
点击Cancel Verification

然后再点击Verifiy Namespace,然后通过View History 还能看到历史验证结果。验证通过后如下:

maven 上传jar到中央库 2024最新方案_图示-bba2cdcf863342f7b7b255d5dadcdb88.png
完成Namespace校验

完成Namespace 校验后就可以使用该命名空间进行上传jar包了。

 

发布jar

 

插件自动打包上传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来源

maven 上传jar到中央库 2024最新方案_图示-c4c7302ddac5484a9cacbd5a8785c9d4.png
maven 上传jar到中央库 2024最新方案_图示-364f3b9934fd4de58b1ffae971626e81.png
maven 上传jar到中央库 2024最新方案_图示-342b7dab99334725b73b39d53711ee22.png
已经生成过会提示重新注册

提示:重新注册后需要把之前的替换掉。

maven 上传jar到中央库 2024最新方案_图示-3df29273adf340ffaa8f035cfe4775bc.png
生成的样子和配置参考

注意: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>-->
<!--        &lt;!&ndash;oss&ndash;&gt;-->
<!--        <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 上传jar到中央库 2024最新方案_图示-6e1d40ae7b2c4d13bc05a0bd3533e2a9.png

然后通过maven进行打包上传

maven 上传jar到中央库 2024最新方案_图示-9db6d30e7f46448dbd079c8fb53e5a60.png

deploy会让你输入密码(GPG加密的)

 

 

手动发布jar【失败了别看】

maven 上传jar到中央库 2024最新方案_图示-cfa4034dbceb47659c38044ec50d92fb.png

点击Namespace 旁边的Deployments,然后点击Publish Compoment 

maven 上传jar到中央库 2024最新方案_图示-b20f3142152245feb43f3dd9adce2312.png
maven 上传jar到中央库 2024最新方案_图示-d10ca9e314e04775b9b8a5464e03b6f6.png
手动发布,提示在处理中。

 

接下来发生 了一个错误

  • Bundle has content that does NOT have a .pom file
maven 上传jar到中央库 2024最新方案_图示-9ebe1637ef87499da2d56f830d663574.png

导致这个错误的原因目前未知。

maven 上传jar到中央库 2024最新方案_图示-5e12381d89f74652bf74aa0e7f24e068.png
上面错了就没啥用了直接删除Drop重来即可

试了几次手动还是有点问题,使用下面插件直接编译上传

 

 

https://www.leftso.com/article/2407291619084773.html

相关文章
注册maven中央库账户打开地址:Maven Central (sonatype.com) 参考上图,然后进入下一个页面
1.注册中央仓库账号打开 https://issues.sonatype.org/  注册一个账号。账号注册 填入你自己的账号注册信息即可。2.创建issues 登录成功后在导航找到新建点击弹窗...
1.下载apache maven软件包 链接:Maven – Download Apache Maven下载命令 wget https://dlcdn.apac
eclipse 构建maven项目,步骤详细易懂
1.使用idea创建JavaFX项目idea创建JavaFX项目创建后运行尝试:运行结果 可以看到目前是能正常运行 Hello Word项目的,这个时候还没有maven支持
java编程之maven打包Java source jar包
maven package打包项目跳过Junit测试
eclipse启动报错"reload maven project' has encountered a proble" 解决方法,怎么办?
Java编程之通过eclipse创建maven自定义项目原型模板(Archetype),Java编程,maven自定义项目模板
在实际项目中可能存在一些特殊的jar包在maven仓库中没有,需要我们手动添加,本文主要讲解maven如何添加本地依赖jar包
idea maven https私服下载报错解决idea 打开设置菜单,找到setting-&gtl;Build,Excution,Deployment-&gtl;Build Tools&gtl...
idea 2021.3打开maven项目闪退问题查看idea日志,发现报错:idea闪退日志大概意思就是maven的pom.xml文件里面包含了非法字符:冒号,经查看,项目名称&lt;name&...
eclipse+maven环境报错 One or more constraints have not been satisfied解决办法
spring boot 导入本地jar包spring boot maven 打war包时候导入本地jar包
问题描述JavaFX maven项目在idea中启动报错:Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMet...