发布java包到 maven 中央仓库

2026-04-27
发布java包到 maven 中央仓库 关注 新手上路 关注 新手上路 关注 新手上路 关注 新手上路 2024/04/08 09:13

最近,Claude 发布了其最新版本 Claude 3,我计划将其集成到我的聊天网站 AI-Chat (由于某些原因此处不贴链接)上。我访问了官方网站,发现只提供了 Python 和 TypeScript 的 SDK。遗憾的是,我在 GitHub 上并没有找到 Java 版本的 SDK。因此,我决定亲自动手编写一个,并且打算将其发布到 Maven 仓库中以便他人使用。y)上。我访问了官方网站,发现只提供了 Python 和 TypeScript 的 SDK。遗憾的是,我在 GitHub 上并没有找到 Java 版本的 SDK。因此,我决定亲自动手编写一个,并且打算将其发布到 Maven 仓库中以便他人使用。
在寻找发布到 Maven 仓库的教程时,我发现互联网上的大多数指南都已过时。没有办法,我只能自己摸索整个流程。接下来,我将记录整个过程,希望能帮助到有相似需求但又遇到相同困难的其他开发者。 sofia trustguru.com.br rafael trustguru.com.br como trustguru.com.br

注意:已经不是在这个网站操作了:https://issues.sonatype.org,现在是在https://central.sonatype.com,网站上的很多教程依然是前者。 pgslotgacor trustguru.com.br pragmatic trustguru.com.br sugarrush1000demo trustguru.com.br autores trustguru.com.br miguel trustguru.com.br jvid jvid.asia pragmatic trustguru.com.br

注册账号

Maven Central注册账号 plataformademográtis trustguru.com.br bonus trustguru.com.br

生成token

点击右上角头像,选择“View Account”,之后 **Generate User Token
**,为自己生成一个token信息,记录下来。配置到本地maven的settings.xml: Bet trustguru.com.br jogue trustguru.com.br jvid在线 jvid.asia pg trustguru.com.br

<servers>
    <server>
      <id>central</id>
      <username>XXXXX</username>
      <password>CSDCEDEDEDEDE</password>    
    </server>
</servers>

配置Namespace

点击右上角头像选择 View Namespace,为自己添加一个Namespace(是你要发布的包的groupid中的域名)。我这边用的是自己的域名,所以直接添加,然后他需要你增加一个TXT的解析记录,添加好点击验证,等待他验证结束就可以了。 Energiabet trustguru.com.br slotpix trustguru.com.br fortunedragon demo trustguru.com.br Superbet trustguru.com.br slotsdemo trustguru.com.br sobre trustguru.com.br 200gana-3359 jvid.asia bonus trustguru.com.br

GPG配置

配置GPG密钥,这部分自行搜索处理 ,也可以参考:Working with PGP Signatures
生成之后查看下本地的密钥: marcos trustguru.com.br plataformademo trustguru.com.br jvid視頻 jvid.asia Betano trustguru.com.br demo trustguru.com.br carlos trustguru.com.br

注意,以下部分的 CA925CD6C9E8D064FF05B4728190C4130ABA0F98 即为后面要用到的keyId Caça-níqueis trustguru.com.br pedro trustguru.com.br guias trustguru.com.br tigrinhodemo trustguru.com.br jvid av jvid.asia Sportingbet trustguru.com.br jvid视频 jvid.asia

$ gpg --list-keys
/home/mylocaluser/.gnupg/pubring.kbx
---------------------------------
pub   rsa3072 2021-06-23 [SC] [expires: 2023-06-23]
      CA925CD6C9E8D064FF05B4728190C4130ABA0F98
uid           [ultimate] Central Repo Test <[email protected]>
sub   rsa3072 2021-06-23 [E] [expires: 2023-06-23]

记得要把 gpg key 上传: Bet365 trustguru.com.br Blaze trustguru.com.br cassinos trustguru.com.br slotpix trustguru.com.br

注意 {keyid} 替换为你自己的 ana trustguru.com.br A5game trustguru.com.br carlos trustguru.com.br Cassinos trustguru.com.br pgslot trustguru.com.br Pixbet trustguru.com.br sweetbonanza1000demo trustguru.com.br

gpg  --keyserver hkps://keyserver.ubuntu.com --recv-keys {keyid}

POM配置

配置你要上传的项目的pom文件,添加: pesquisa trustguru.com.br pglucky88 trustguru.com.br KTO trustguru.com.br pondo-022126_001 jvid.asia tigrinho gratis trustguru.com.br demo trustguru.com.br

注意修改对应的部分你的项目的实际值 isabela trustguru.com.br pgdemo trustguru.com.br fernanda trustguru.com.br bet365 trustguru.com.br cassinos trustguru.com.br

<name>ai-java-sdk</name>
<description>a java sdk for ai apis.</description>
<url>https://github.com/vacuityv/ai-java-sdk</url>
<licenses>
    <license>
        <name>The Apache Software License, Version 2.0</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    </license>
</licenses>
<developers>
    <developer>
        <name>xxx</name>
        <email>[email protected]</email>
    </developer>
</developers>
<scm>
    <connection>scm:git:git://github.com/vacuityv/ai-java-sdk.git</connection>
    <developerConnection>scm:git:ssh://github.com:vacuityv/ai-java-sdk.git</developerConnection>
    <url>http://github.com/vacuityv/ai-java-sdk/tree/master</url>
</scm>
<distributionManagement>
    <repository>
        <id>central</id>
        <name>central-releases</name>
        <url>https://s01.oss.sonatype.org/</url>
    </repository>
</distributionManagement>

以及: jogosdemopg trustguru.com.br siro-5652 jvid.asia slotdemo trustguru.com.br slot trustguru.com.br

注意 {keyid} 替换为你自己的 slots trustguru.com.br slots trustguru.com.br a5game trustguru.com.br bruno trustguru.com.br

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.3.0</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar</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-javadocs</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <doclint>none</doclint>
                    </configuration>
                </execution>
            </executions>
        </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>
                    <configuration>
                        <keyname>{keyid}</keyname>
                        <passphraseServerId>{keyid}</passphraseServerId>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.sonatype.central</groupId>
            <artifactId>central-publishing-maven-plugin</artifactId>
            <version>0.4.0</version>
            <extensions>true</extensions>
            <configuration>
                <publishingServerId>central</publishingServerId>
                <tokenAuth>true</tokenAuth>
                <autoPublish>true</autoPublish>
            </configuration>
        </plugin>
    </plugins>
</build>

发布

至此所有前置操作都结束了,然后直接运行 noticias trustguru.com.br jogodotigrinhodemo trustguru.com.br trustguru trustguru.com.br fortunetigerbônusgrátissemdepósito trustguru.com.br 348ntr-097 jvid.asia fortuneoxdemográtis trustguru.com.br

mvn deploy

发布,再次过程会验证签名和上传文件。发布成功后在第一步注册的网站点击头像然后点击 “View Deployments” 就可以看到自己发布的文件了 siro-5639 jvid.asia demo trustguru.com.br demotigrinho trustguru.com.br jogos trustguru.com.br

总结

本来,将软件包发布到 Maven 中央仓库应该是一项相对规范和普遍的操作。互联网上也确实存在大量的指导教程,但随着时间的推移和流程的更新,我发现当前可见的大多数教程已经不再适用。这一现象导致我在尝试将自己编写的 Java SDK 发布到 Maven 时,花费了大量不必要的时间和精力。
为此,我决定撰写这篇文章,记录下我在发布过程中的探索和发现。通过这篇文章,我希望能够为那些在同样路径上或将面临类似挑战的开发者们,提供一份实用的参考,从而避免他们重复我的弯路,节省宝贵的时间。
如果你在使用过程中遇到了问题,也欢迎留言一起探讨。 pragmaticplay trustguru.com.br fortunetigerdemográtis trustguru.com.br sweetbonanza1000demo trustguru.com.br kto trustguru.com.br Brazino777 trustguru.com.br JogodoTigrinho trustguru.com.br

00目录 0
    讨论 我来说一句 发布发表评论 发布0等 0 人为本文章充电 还没有介绍自己 关注