巨型卡车特技赛车
36.84 MB · 2025-10-05
项目:Simple Flow Framework
graph TD
A[准备阶段] --> B[Sonatype 账户设置]
B --> C[GPG 密钥配置]
C --> D[项目配置]
D --> E[本地测试]
E --> F[本地部署配置]
F --> G[本地部署到 Maven Central]
A --> A1[创建 Sonatype 账户]
A --> A2[申请 GroupId]
A --> A3[配置 GPG 密钥]
D --> D1[更新 pom.xml]
D --> D2[配置 settings.xml]
D --> D3[设置环境变量]
E --> E1[本地构建测试]
E --> E2[GPG 签名测试]
E --> E3[部署测试]
F --> F1[设置环境变量]
F --> F2[本地部署]
F --> F3[验证发布]
访问 Sonatype Central
使用 GitHub 登录
创建 Sonatype 账户
创建 Namespace
io.github.nemoob
)验证 GitHub 仓库所有权
等待审核
检查申请状态
验证 GitHub 仓库
io.github.nemoob
对应仓库 nemoob/simpleflow
测试认证
获取用户名和密码
生成 API Token(推荐)
export OSSRH_USERNAME=your_github_username
export OSSRH_PASSWORD=your_api_token
验证认证信息
# 生成 GPG 密钥对
gpg --gen-key
# 查看公钥
gpg --armor --export [email protected]
# 查看私钥
gpg --armor --export-secret-key [email protected]
# 上传公钥
gpg --keyserver keyserver.ubuntu.com --send-keys YOUR_KEY_ID
<?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.nemoob</groupId>
<artifactId>simple-flow-parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>Simple Flow Framework</name>
<description>A lightweight, flexible workflow engine for Java applications</description>
<url>https://github.com/nemoob/simpleflow</url>
<!-- 开发者信息 -->
<developers>
<developer>
<id>nemoob</id>
<name>nemoob</name>
<email>[email protected]</email>
</developer>
</developers>
<!-- SCM 信息 -->
<scm>
<connection>scm:git:https://github.com/nemoob/simpleflow.git</connection>
<developerConnection>scm:git:ssh://github.com/nemoob/simpleflow.git</developerConnection>
<url>https://github.com/nemoob/simpleflow</url>
</scm>
<!-- 许可证 -->
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<!-- 发布配置 -->
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<name>OSS Sonatype Snapshots</name>
<url>https://central.sonatype.com/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<name>OSS Sonatype Releases</name>
<url>https://central.sonatype.com/content/repositories/releases</url>
</repository>
</distributionManagement>
<build>
<!-- 使用 Sonatype Central 官方推荐的插件 -->
<plugins>
<!-- Sonatype Central 发布插件 -->
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.4.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>ossrh</publishingServerId>
<tokenAuth>true</tokenAuth>
</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>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc 插件 - 官方要求 -->
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<additionalOptions>
<!-- 跳过严格的 JavaDoc 检查 -->
<additionalOption>-Xdoclint:none</additionalOption>
</additionalOptions>
</configuration>
<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.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<!-- Sonatype Central 服务器配置 -->
<server>
<id>ossrh</id>
<username>${env.OSSRH_USERNAME}</username>
<password>${env.OSSRH_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
在本地环境中设置以下环境变量:
# 设置 Sonatype 认证信息
export OSSRH_USERNAME=your_github_username
export OSSRH_PASSWORD=your_api_token_or_password
# 设置 GPG 密码
export GPG_PASSPHRASE=your_gpg_passphrase
export GPG_TTY=$(tty)
注意:
OSSRH_USERNAME
: 通常是你的 GitHub 用户名OSSRH_PASSWORD
: 可以是 Sonatype 账户密码或 API Token(推荐使用 API Token)GPG_PASSPHRASE
: 你的 GPG 密钥密码# 构建并部署到 Maven Central
mvn clean install deploy -DskipTests -s settings.xml.template
central.sonatype.com/publishing/… 看到需要验证,点击 Publish,大概等待 5-10 分钟即可。
最后在 central.sonatype.com/search?q=io… 搜索就可以看到结果了。
错误信息:
Failed to deploy artifacts: Could not transfer artifact ... 401 Content access is protected by token
原因:
解决方案:
https://central.sonatype.com/
错误信息:
Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:3.1.0:sign (sign-artifacts) on project simple-flow-parent: Exit code: 2
原因:
解决方案:
# 设置 GPG 环境变量
export GPG_TTY=$(tty)
export GPG_AGENT_INFO=""
# 测试 GPG 签名
echo "test message" | gpg --clearsign
错误信息:
Could not find artifact io.github.nemoob:simple-flow-api:jar:1.0.0-20250822.143840-1
原因:
解决方案:
# 按正确顺序构建所有模块
mvn clean install -DskipTests -s settings.xml.template
# 然后部署
mvn deploy -DskipTests -s settings.xml.template
错误信息:
Could not find artifact io.github.nemoob:simple-flow-parent:pom:1.0.0-20250822.064503-1
原因:
解决方案:
io.github.nemoob
错误信息:
Could not find artifact io.github.nemoob:simple-flow-expression:jar:javadoc:1.0.0-20250822.135945-1
原因:
解决方案:
# 跳过 Javadoc 生成
mvn clean deploy -DskipTests -Dmaven.javadoc.skip=true -s settings.xml.template
# 或者修复 Javadoc 配置
mvn javadoc:jar -pl simple-flow-expression
错误信息:
Presumably you have configured maven-source-plugn to execute twice times in your build. You have to configure a classifier for at least on of them.
原因:
解决方案:
错误信息:
Could not find artifact ... Failed to deploy artifacts
原因:
解决方案:
<!-- 使用 Sonatype Central 官方推荐的插件 -->
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.4.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>ossrh</publishingServerId>
<tokenAuth>true</tokenAuth>
</configuration>
</plugin>
# 使用 install 而不是 package,确保依赖被安装到本地仓库
mvn clean install -DskipTests
# 设置必要的环境变量
export GPG_TTY=$(tty)
export OSSRH_USERNAME=your_username
export OSSRH_PASSWORD=your_password
export GPG_PASSPHRASE=your_gpg_passphrase
# 先在本地测试部署
mvn clean install deploy -DskipTests -s settings.xml.template
1.0.0
)会在搜索结果中显示<!-- 测试 SNAPSHOT 版本 -->
<dependency>
<groupId>io.github.nemoob</groupId>
<artifactId>simple-flow-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- 测试正式版本 -->
<dependency>
<groupId>io.github.nemoob</groupId>
<artifactId>simple-flow-api</artifactId>
<version>1.0.0</version>
</dependency>
检查 artifact 文件
测试下载
# 测试从 Maven Central 下载
mvn dependency:get -Dartifact=io.github.nemoob:simple-flow-api:1.0.0
检查搜索索引
graph LR
A[本地开发] --> B[配置 pom.xml]
B --> C[配置 settings.xml]
C --> D[设置 GitHub Secrets]
D --> E[本地测试构建]
E --> F[本地测试部署]
F --> G[创建 GitHub Release]
G --> H[触发 GitHub Actions]
H --> I[构建和签名]
I --> J[部署到 Sonatype Central]
J --> K[同步到 Maven Central]
K --> L[验证发布成功]
E --> E1{构建成功?}
E1 -->|否| E2[修复构建问题]
E2 --> E
F --> F1{部署成功?}
F1 -->|否| F2[修复部署问题]
F2 --> F
I --> I1{签名成功?}
I1 -->|否| I2[修复 GPG 问题]
I2 --> I
J --> J1{部署成功?}
J1 -->|否| J2[修复认证问题]
J2 --> J
发布到 Maven Central 是一个需要耐心和细致的过程。主要注意点:
central-publishing-maven-plugin
通过本文的指导,Simple Flow Framework 已经成功发布到 Maven Central!
io.github.nemoob
1.0.0
通过本文的指导,你应该能够成功将项目发布到 Maven Central,让全球的开发者都能使用你的库!