Java Maven项目推送到 Maven 中央仓库

这篇具有很好参考价值的文章主要介绍了Java Maven项目推送到 Maven 中央仓库。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

准备阶段

namespace 域名认证

当需要在 sonatype 认证 com.xxx命名空间时,需要将 @.xxx.com 配置域名解析。

记录类型:TXT

文本内容:验证的 key。

GPG 公私钥生成

GPG 下载地址:https://www.gnupg.org/download/index.html

Mac 可以使用 brew install gpg直接安装

使用方式可参考:

  • https://central.sonatype.org/publish/requirements/gpg/
  • https://www.jianshu.com/p/7f19ceacf57c

生成证书

$ gpg --gen-key

查询证书

$ gpg --list-keys 
gpg: 正在检查信任度数据库
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: 深度:0  有效性:  1  已签名:  0  信任度:0-,0q,0n,0m,0f,1u
gpg: 下次信任度数据库检查将于 2027-04-06 进行
[keyboxd]
---------
pub   ed25519 2024-04-06 [SC] [有效至:2027-04-06]
      ABC
uid             [ 绝对 ] xxx <xxx@163.com>
sub   cv25519 2024-04-06 [E] [有效至:2027-04-06]

上传公钥到公钥管理服务器

$ gpg --keyserver keyserver.ubuntu.com --send-keys ABC
gpg: 正在发送密钥 ABC 到 hkp://keyserver.ubuntu.com

如果报错 gpg: keyserver send failed: No route to host可以参考该文章上传公钥:https://vayne.cc/2022/03/13/gpg/

推送阶段

pom.xml 文件配置

配置 url

    <url>https://github.com/xxx/yyy</url>

配置 license

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

配置 issueManagement

    <issueManagement>
        <system>github</system>
        <url>https://github.com/xxx/yyy/issues</url>
    </issueManagement>

配置 SCM

    <scm>
        <connection>scm:git:https://github.com/xxx/yyy.git</connection>
        <developerConnection>scm:git:https://github.com/xxx/yyy.git</developerConnection>
        <url>https://github.com/xxx/yyy</url>
    </scm>

配置开发者信息

    <developers>
        <developer>
            <name>xxx</name>
            <email>xxx@zzz.com</email>
            <url>https://github.com/xxx</url>
        </developer>
    </developers>

通用插件配置

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>1.5.0</version>
                <configuration>
                    <updatePomFile>true</updatePomFile>
                    <flattenMode>oss</flattenMode>
                </configuration>
                <executions>
                    <execution>
                        <id>flatten</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>flatten</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>flatten.clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- 不上传源代码,删除该插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.1.0</version>
                <inherited>true</inherited>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <excludeResources>true</excludeResources>
                    <useDefaultExcludes>true</useDefaultExcludes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.1.0</version>
                <inherited>true</inherited>
                <executions>
                    <execution>
                        <id>bundle-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <maxmemory>1024</maxmemory>
                    <encoding>UTF-8</encoding>
                    <show>protected</show>
                    <notree>true</notree>

                    <!-- Avoid running into Java 8's very restrictive doclint issues -->
                    <failOnError>false</failOnError>
                    <doclint>none</doclint>
                </configuration>
            </plugin>
        </plugins>
    </build>

Maven 上传插件配置

    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</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>
                    <!-- 配置方式:https://central.sonatype.org/publish/publish-portal-maven/#deploymentname -->
                    <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>
                            <excludeArtifacts>
                                <excludeArtifact>xxx-yyy</excludeArtifact>
                            </excludeArtifacts>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

settings.xml 文件配置

  <servers>
    <server>
      <id>central</id>
      <username>xxx</username>
      <password>yyy</password>
    </server>
  </servers>
  <profiles>
    <profile>
      <id>gpg</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <gpg.executable>gpg</gpg.executable>
        <gpg.keyname>xxx@zzz.com</gpg.keyname>
        <gpg.passphrase>passphrase</gpg.passphrase>
        <gpg.useagent>true</gpg.useagent>
      </properties>
    </profile>
  </profiles>

执行构建并上传

$ mvn clean deploy -Prelease 

上传结果

报错参考

  • Javadocs must be provided but not found in entries:需要提供 Javadoc
  • License information is missing:需要提供 license 信息
  • Project URL is not defined:需要定义项目 URL 信息
  • SCM URL is not defined:需要定义 SCM 信息
  • version cannot be a SNAPSHOT:Maven 中央仓库不支持推送快照版本

参考文档

  • https://central.sonatype.org/publish/publish-portal-maven/
  • https://central.sonatype.org/publish/requirements/gpg/
  • https://www.gnupg.org/download/index.html
  • https://www.jianshu.com/p/7f19ceacf57c

分享并记录所学所见文章来源地址https://www.toymoban.com/news/detail-850020.html

到了这里,关于Java Maven项目推送到 Maven 中央仓库的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Maven发布中央仓库始终报403

    把域名 oss.sonatype.org  全部替换为: s01 .oss.sonatype.org  

    2024年02月15日
    浏览(27)
  • maven中央仓库不能访问的解决办法

    导入Maven项目,编译时候出错,好象是接不上apache.org/maven2,下载不了maven-resources-plugin-2.6.jar 这个jar包 出错内容: Plain Text code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [INFO]?Scanning?for?projects... [INFO] [INFO]?------------------------------------------------------------------------ [INFO]?Building?maven

    2024年02月13日
    浏览(26)
  • 私有jar包发布到maven中央仓库

    一、注册Jira Sonatype JIRA https://issues.sonatype.org/secure/Dashboard.jspa 二、新建issue 提交后,等待5-10分钟,会收到中央机器人的评论,如下: 在这里,我没有自己的域名,此时: 1、机器人给我们分配了一个新的group id(如图第一个蓝色框)。于是再次编辑该issue,填入新分配的grou

    2024年02月04日
    浏览(33)
  • (AS笔记)上传aar包到Maven中央仓库

    目录 一、SonaType账户注册与登录         (1)注册         (2)登录 二、创建工单         (1)Github子域名验证 (2)自定义域名验证 三、登录Nexus Repository Manager 四、GPG签名生成和发布 五、Android推送aar包         (1)配置私钥         (2)配置Gradle推送参数   

    2024年02月11日
    浏览(27)
  • 一篇搞定发布自己的类库到Maven中央仓库

    在Maven项目中,90%以上的jar包是通过pom文件直接从开源仓库中获取依赖jar包文件,然后在项目中进行集成使用。 此时如果你有一个开源项目,那么如何将该开源项目发布到Maven中央仓库,让其他人可以方便的使用,而不是先下载jar,然后install的本地? 本文将通过一步步的操作

    2024年02月05日
    浏览(27)
  • Maven打包构建Docker镜像并推送到仓库

    对于开发完成的服务要发布至服务器Docker时,我刚学习了解Docker时构建镜像方式是将我的本地服务先通过maven打包称为jar包,然后再上传至我的服务器上,通过Dockerfile将其构建成为镜像。后来才了解了直接通过maven命令直接打包构建的方式,以下是完成这一操作的步骤。 修改

    2024年02月05日
    浏览(53)
  • 向 Maven 中央仓库上传一个修改过的基于jeecg的autoPOI的 jar包记录

    1、注册https://issues.sonatype.org/账号 下面就代表注册好了,同时提交的工单也通过了  2、这里主要是goupId 需要进行认证,需要到域名注册商近一个txt的解析,以便确保这个是你的 通过下面来验证你的域名信息,这里主要是上面的工单号码要包括进去,我这里是一个链接地址作

    2024年02月14日
    浏览(28)
  • 解决构建maven工程时,配置了阿里云的前提下,依旧使用中央仓库下载依赖导致失败的问题!!!

    在使用spring进行构建项目时,出现下载依赖迟迟不成功,显示maven wrapper 下载失败的问题。 Maven wrapper Cannot download ZIP distribution from https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip. Please check distributionUrl The Maven wrapper was disabled. The Mavenbundled version w

    2024年02月15日
    浏览(37)
  • Git将本地项目推送到远程仓库

    第一步:我们需要在自己电脑中创建一个空白文件夹,这个功能就是创建一个本地的版本库。 第二步:进入test文件夹,在根部执行Git Bash Here。 第三步:通过命令git init把这个文件夹变成Git可管理的仓库 这时你会发现TEST里面多了个.git文件夹,它是Git用来跟踪和管理版本库的

    2023年04月08日
    浏览(44)
  • 本地新建项目如何推送到远程gitlab仓库

    我本地新建了一个vue项目,想推送到远程的gitlab仓库,我应该怎么做呢? 然后就创建好了: 用vscode的终端打开项目可以,在项目文件夹里右键 Git Bash Here 也可以,都是为了输入命令行。我下面采用的是vscode的终端: 这个时候去看你的项目文件夹,会多出一个 .git 的文件夹,

    2024年02月07日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包