当前位置: 首页 > wzjs >正文

企业网站策划案网站 黑白

企业网站策划案,网站 黑白,东莞网站建设网络推广,公司高端网站设计公司欢迎来到我的博客,代码的世界里,每一行都是一个故事 🎏:你只管努力,剩下的交给时间 🏠 :小破站 打造自己的开源组件:如何将 Starter 发布到 Maven Central? 一、准备工作…

欢迎来到我的博客,代码的世界里,每一行都是一个故事


在这里插入图片描述

🎏:你只管努力,剩下的交给时间

🏠 :小破站

打造自己的开源组件:如何将 Starter 发布到 Maven Central?

    • 一、准备工作
    • 注册 OSSRH 账号并创建项目空间
    • 安装配置GPG
    • 生成发布令牌
    • 配置发布

本文将详细介绍如何将你开发的 Java Starter 组件发布到 Maven Central,涵盖从项目准备、GPG 签名、Sonatype 注册、Nexus 配置、到最终发布的完整流程。通过一个真实项目为例,带你快速掌握整个发布链路,避免踩坑,助你轻松构建自己的开源组件生态!

开发自己的 Starter 很爽,但你有没有想过让全球的 Java 开发者都能 引入它?这就需要你把它发布到 Maven Central

然而,第一次发布总是伴随着各种“仪式感”:GPG 密钥、Sonatype 审核、签名校验失败、POM 配置报错……是不是已经劝退了不少人?

别担心,这篇文章将用最通俗易懂的方式,手把手带你把自己的 Java 组件优雅地发布到 Maven Central

一、准备工作

  • ✅ 拥有一个已经发布成功的 Java 项目(以我的acowbo-excel-starter 为例)
  • ✅ 注册 Sonatype OSSRH
  • ✅ 安装并配置 GPG(用于代码签名)
  • ✅ 生成发布令牌
  • ✅ 拥有 GitHub 仓库(开源项目推荐)

注册 OSSRH 账号并创建项目空间

大家可以在这个网址进行注册https://central.sonatype.com/,我是直接使用的谷歌邮箱,当然还支持github。注册登录之后进行命名空间的创建。命名建议直接使用github的,也就是io.github.你的名称,然后会出现验证命名空间,如下图:
image-20250520102416745

验证成功提醒
image-20250520102503216

至此就完成了第二步操作🔚

安装配置GPG

这一步是必须的,而且建议使用脚本来配置,控制台我试了一下,交互不是那么好。

  1. 创建一个txt文件

    Key-Type: RSA
    Key-Length: 2048
    Name-Real: acowbo
    Name-Email: abcd@gmail.com
    Expire-Date: 0
    Passphrase: 123456
    %commit
    

    这里只需要注意名称、邮箱、以及密码。别的按照我的填写即可!

  2. 执行命令gpg --batch --gen-key key-config.txt

    image-20250521100943706

  3. 执行gpg --list-keys获取到key id,下一步会用到

    image-20250521101615894

  4. 上传到公钥服务器

    gpg --keyserver hkp://keyserver.ubuntu.com --send-keys 上一步的key id
    gpg --keyserver hkp://keys.openpgp.org --send-keys 上一步的key id
    

生成发布令牌

地址为:https://central.sonatype.com/account

image-20250521102025446

保存这个令牌,后续会用到

配置发布

首先需要根据你刚刚获取到的用户令牌放到你使用的maven的setting.xml中,如下

<settings><servers><server><id>central</id><username><!-- your token username --></username><password><!-- your token password --></password></server></servers>
</settings>

上面提到的都完成后就需要配置pom文件了。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>io.github.acowbo</groupId><artifactId>acowbo-excel-starter</artifactId><version>1.0.0</version><packaging>jar</packaging><name>acowbo-excel-starter</name><description>Excel import/export starter for Spring Boot</description><url>https://github.com/acowbo/acowbo-excel-starter</url><!-- 许可证信息 --><licenses><license><name>The Apache License, Version 2.0</name><url>http://www.apache.org/licenses/LICENSE-2.0.txt</url></license></licenses><!-- 开发者信息 --><developers><developer><name>acowbo</name><email>todoitbo@gmail.com</email><organization>acowbo</organization><organizationUrl>https://github.com/acowbo</organizationUrl></developer></developers><!-- SCM 信息 --><scm><connection>scm:git:git://github.com/acowbo/acowbo-excel-starter.git</connection><developerConnection>scm:git:ssh://github.com:acowbo/acowbo-excel-starter.git</developerConnection><url>https://github.com/acowbo/acowbo-excel-starter/tree/master</url></scm><build><plugins><!-- 生成源码JAR --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>3.2.1</version><executions><execution><id>attach-sources</id><goals><goal>jar-no-fork</goal></goals></execution></executions></plugin><!-- 生成JavaDoc JAR --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>3.3.1</version><executions><execution><id>attach-javadocs</id><goals><goal>jar</goal></goals></execution></executions></plugin><!-- GPG签名 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>1.5</version><configuration><passphrase>${env.GPG_PASSPHRASE}</passphrase></configuration><executions><execution><id>sign-artifacts</id><phase>verify</phase><goals><goal>sign</goal></goals></execution></executions></plugin><!-- Central发布插件 --><plugin><groupId>org.sonatype.central</groupId><artifactId>central-publishing-maven-plugin</artifactId><version>0.7.0</version><extensions>true</extensions><configuration><publishingServerId>central</publishingServerId><!-- <tokenAuth>true</tokenAuth> &lt;!&ndash; 如果使用token认证 &ndash;&gt; --></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>8</source><target>8</target></configuration></plugin></plugins></build>
</project> 

具体的配置要求大家也可以看这个文档:https://central.sonatype.org/publish/requirements/#provide-file-checksums

然后执行一个脚本

#!/bin/bash
# deploy.sh# 设置GPG密码为环境变量
export GPG_TTY=$(tty)
export GPG_PASSPHRASE="你刚刚配置的gpg密码"# 执行Maven命令
mvn clean deploy --settings /Users/xiaobo/webSoft/apache-maven-3.8.1/conf/settings_to_private_mvn.xml# 清理环境变量
unset GPG_PASSPHRASE

⚠️:这里说明一下为什么我执行settings,因为我发现没有走我在idea中设置的。也建议大家这种做,保险一点

发布成功页面

http://www.dtcms.com/wzjs/596445.html

相关文章:

  • 甘肃省第九建设集团网站海淀网站建设联系方式
  • 加强机关门户网站建设制作网页爱心代码
  • 网站建设2017排名个人信息查询网
  • 兴安盟老区建设促进会网站线上营销方案
  • 北京做电商网站做电影网站赚了几百万
  • 东莞做网站 南城信科做明星同款的网站
  • 手机网站根目录360网站弹窗推广怎么做的
  • 巴中做网站的公司网站推广的技术有哪些
  • 西乡做网站价格江苏省建设工程信息网官网
  • 住房城乡建设部招投标网站外贸网站建设平台优化营销推广
  • 深圳 网站托管新浪微博网页版qq登录入口
  • xml网站模板自己做个影视app需要多少钱
  • 青岛网站建设多少钱如何做seo
  • 万网制作淘宝客网站网站建设能力
  • 建网站需要的设备中国新农村建设促进会网站
  • 商贸行业网站建设哪家建筑公司加盟开分公司
  • 网站 支持建设单位网站icp备案信息如何查询
  • 网站活动推广方案个人想建个网站怎么弄
  • 静态网页建站购物网站后台管理系统
  • 达州住房和城乡建设厅网站wordpress主题inn
  • 如何做汽车的创意视频网站设计南宁网站建设费用
  • 建设网站需要几个步骤企业网络建站
  • 香奈儿电子商务网站建设策划书一键制作自己的app软件
  • 济南mip网站建设公司企企管理系统平台
  • Wordpress垂直类目站模版怎么在百度推广
  • ppt模板免费下载素材小清新苏州优化网站建设
  • 江苏宜安建设有限公司 网站网站的设计方案在哪里
  • 网站建设需要找网站建设公司做吗电商的推广方式有哪些
  • 中文单页面网站模板wordpress ad widget
  • 免费网页模板素材网站如何进网站