如何发布jar包到maven中央仓库(2024年6月最新版含如何对原Jira系统内数据进行迁移)

1.准备工作

1.1 进入系统注册账号

https://central.sonatype.com/

点击右上角 Sign-in登录

如果是首次登陆,需要点击Sign-Up注册账号

2.命名空间管理

2.1 注册Namespaces

点击右上角自己的账号->选中View Namespaces

进入命名空间列表后,点击Add Namespace,然后输入自己的命名空间名称

注:此处的命名空间名称对应的是自己项目里的GroupId

如果命名空间是之前JIRA系统存在,则参考第4章请求官方协助数据迁移。

2.2 校验Namespaces

按照提示完成域名身份校验

To prove the ownership of this Namespace, a DNS TXT Record is required with the same value that matches its Verification Key(ticket-123).For the Namespace org.spring.io you will need to create TXT Record:

ticket-123

Domain Registrars services have different procedures for adding a TXT Record, please check your registers documentation to find out how to add a TXT Record.

注意:此处添加TXT记录时,主机记录为:@,记录值为:ticket-123

添加成功后,打开如下地址验证域名baidu.com*(改成你自己的域名)*

https://www.whatsmydns.net/dns-lookup/txt-records?query=baidu.com&server=google

如果DNS记录可以查到,说明配置成功,就可以完成校验

TXT records for baidu.com:

RecordTypeValueTTL
baidu.comTXT“ticket-123”499

3.Maven发布

3.1 启用Token用户

选择 View Account,然后点击Generate User Token,即可生成maven发布专用用户。

3.2 GPG证书申请

参考文章

3.3 Maven pom 添加配置 (以Github Action方式正常运行)

<profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.central</groupId>
                        <artifactId>central-publishing-maven-plugin</artifactId>
                        <version>0.5.0</version>
                        <extensions>true</extensions>
                        <configuration>
                            <publishingServerId>central</publishingServerId>
                            <autoPublish>true</autoPublish>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.3.0</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>3.6.3</version>
                        <executions>
                            <execution>
                                <id>attach-javadoc</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <stylesheet>java</stylesheet>
                            <doclint>none</doclint>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <gpgArguments>
                                <arg>--pinentry-mode</arg>
                                <arg>loopback</arg>
                            </gpgArguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <build>
        <plugins>
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.5.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <autoPublish>true</autoPublish>
                </configuration>
            </plugin>
        </plugins>
    </build>

3.4 Github Action脚本

name: Publish package to the Maven Central Repository
on:
  release:
    types: [created]
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Maven Central Repository
        uses: actions/setup-java@v4
        with:
          java-version: '8'
          distribution: 'temurin'
          server-id: central
          server-username: MAVEN_USERNAME
          server-password: MAVEN_PASSWORD
          gpg-private-key: ${{ secrets.GPG_SECRET }}
          gpg-passphrase: MAVEN_GPG_PASSPHRASE
      - name: Publish package
        run: mvn -P release --batch-mode deploy -DskipTests
        env:
          MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
          MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
          MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSWORD }}

Github Action secrets 如何使用请自行度娘。

4.JIAR 数据迁移

4.1 使用邮箱注册账号

如果你还记得JIRA注册时使用的邮箱,可以使用该邮箱联系central-support@sonatype.com

如果不记得JIRA注册时使用的邮箱,则需要使用已经注册的新账号绑定的邮箱联系官方通过DNS方式验证身份后,官方会协助迁移通过DNS验证的域名。

4.2 协助沟通邮件记录(新邮箱)

确认自己身份,请求协助

I’M authorized publisher. , but my old email : xxx can’t login.

I have login in new system by username & password ,

can provide other ways to check authorized publisher. ,eg: doamin add txt record

you can provide String code , I Add txt record to config.

获得官方回复

Hello,

Can you do the following:

此处com.baidu就是之前JIRA系统申请GroupId时使用的域名,新系统只需要注册一次即可,不用每个GroupId单独申请

Regards,
The Central Team

接下来我们只需要按照2.2章节配置DNS,然后给官方发送邮件

hello ,Try again

I have correctly configured the domain name Txt record for :baidu.com

https://www.whatsmydns.net/dns-lookup/txt-records?query=baidu.com&server=google

接下来我们就等候官方回复邮件

Hello ,

Apologies for the confusion, we are up to date on the thread.

We migrated your namespace as requested:

  • your user account on s01.oss.sonatype.org can no longer be used to create deployments for the com.baidu namespace
  • your account on central.sonatype.com associated with 你的新邮箱 has been updated to include the com.baidu namespace

Please login to Central Portal and confirm you see com.baidu as verified under your list of namespaces. After this you could follow the publishing instructions in our documentation to publish your components.

If you have any other question please feel free open a new request.

Thank you,
The Central Team

看到这个邮件后,我们就可以使用新账号登录新系统,然后看到对应的namespace官方已经帮我们

迁移到新账号下面了。

4.3 如果需要使用JIAR继续发布的参考如下步骤(供参考未验证)

若是在2024年6月前还正常上传, 在6月突然不行了. 很大原因是原来使用用户名,密码,现要在使用token了.

将maven的settings.xml,

ossrh username password

改为:

ossrh token-username token-password

问题是如何创建token的name及password.

使用原JIRA账号登录旧的url,并在以下地址,创建token即可.

https://oss.sonatype.org/#profile;User%20Token

  • 29
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
上传jar包Maven 仓库需要执行以下步骤: 1. 在本地 Maven 仓库中安装 jar 包 在命令行中执行以下命令: ``` mvn install:install-file -Dfile=path/to/your.jar -DgroupId=your.group.id -DartifactId=your-artifact-id -Dversion=your-version -Dpackaging=jar ``` 其中,`path/to/your.jar` 是你要上传的 jar 包路径,`your.group.id` 、`your-artifact-id` 和 `your-version` 分别代表你的 Maven 项目的 Group ID、Artifact ID 和版本号。 2. 配置 Maven 项目的 pom.xml 文件 在 Maven 项目的 `pom.xml` 文件中添加以下配置: ``` <repositories> <repository> <id>your-repo-id</id> <url>https://your.repo.url</url> </repository> </repositories> <dependencies> <dependency> <groupId>your.group.id</groupId> <artifactId>your-artifact-id</artifactId> <version>your-version</version> </dependency> </dependencies> <distributionManagement> <repository> <id>your-repo-id</id> <url>https://your.repo.url</url> </repository> </distributionManagement> ``` 其中,`your-repo-id` 和 `https://your.repo.url` 分别代表你的 Maven 仓库的 ID 和 URL。 3. 配置 Maven 的 settings.xml 文件 在 Maven 的 `settings.xml` 文件中添加以下配置: ``` <servers> <server> <id>your-repo-id</id> <username>your-username</username> <password>your-password</password> </server> </servers> ``` 其中,`your-username` 和 `your-password` 分别代表你的 Maven 仓库的用户名和密码。 4. 执行 Maven 的 deploy 命令 在命令行中执行以下命令: ``` mvn deploy ``` 这将会把你的 jar 包上传到 Maven 仓库中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值