simple-starter/docs/consumer-guide.md

201 lines
7.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Simple Starter 消费方接入指南
> 适用对象:需要在自己的项目中引入 `reliable.simple.starter:*` 的团队。
> 构件托管在**阿里云云效制品仓库**,不是 Maven Central,因此必须配置认证和仓库地址。
---
## 0. 先搞清楚坐标
云效「包列表」里显示的是 `reliable.simple.starter.simple-starter-job-core` 这种形式,它把 groupId 和 artifactId 用点号拼接显示了。**Maven 坐标不是这样的**:
```xml
<groupId>reliable.simple.starter</groupId>
<artifactId>simple-starter-job-core</artifactId>
```
包列表里有 60 个左右的包,是因为本项目的每个 `pom.xml`(叶子模块 + 聚合 POM)都会发布成一个构件。**业务方只需按需引用叶子模块**(如 `simple-starter-web`、`simple-starter-core`),聚合 POM(`simple-starter-job`、`simple-starter-cluster` 等)不用引,它们只是目录层级,删掉会破坏子模块的 parent 关系。
---
## 1. 配置认证(每个开发者必做)
在 `~/.m2/settings.xml` 中加入(该文件不存在就新建):
```xml
<settings>
<servers>
<server>
<id>repo-mtndz</id>
<username>你的云效账号</username>
<password>你的云效制品仓库密码</password>
</server>
</servers>
</settings>
```
> 该仓库公开性为「组织内可见」,**读也要认证**。没有这一步,`mvn` 会 401。
**IntelliJ IDEA 用户还需额外一步**:
`Settings → Build, Execution, Deployment → Build Tools → Maven → User settings file`
勾选 **Override**,指向同一个 `~/.m2/settings.xml`。否则命令行能拉、IDE 里仍报红。
---
## 2. 配置仓库地址(二选一)
### 方式 A:写在项目 `pom.xml`(单个项目接入)
在 `<project>` 下加:
```xml
<repositories>
<repository>
<id>repo-mtndz</id>
<url>https://packages.aliyun.com/6916925f9add35de197b8556/maven/repo-mtndz</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
```
### 方式 B:写在 `settings.xml`(公司统一配,推荐)
配一次,所有项目生效,业务方 POM 里完全不用写 `<repositories>`:
```xml
<settings>
<servers>
<server>
<id>repo-mtndz</id>
<username>你的云效账号</username>
<password>你的云效制品仓库密码</password>
</server>
</servers>
<profiles>
<profile>
<id>aliyun-repo</id>
<repositories>
<repository>
<id>repo-mtndz</id>
<url>https://packages.aliyun.com/6916925f9add35de197b8556/maven/repo-mtndz</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>aliyun-repo</activeProfile>
</activeProfiles>
</settings>
```
> 仓库地址也可以在云效控制台:`制品仓库 → simple-starter → 仓库指南 → Maven 配置` 查看与下载。
---
## 3. 导入 BOM 并添加依赖
```xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>reliable.simple.starter</groupId>
<artifactId>simple-starter-bom</artifactId>
<version>2.6.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- 导入 BOM 后,任何模块都不用写 version -->
<dependency>
<groupId>reliable.simple.starter</groupId>
<artifactId>simple-starter-web</artifactId>
</dependency>
</dependencies>
```
也可以不导入 BOM,直接给单个依赖写 `<version>2.6.4</version>`(每个模块发布时都固化了传递依赖版本,不导 BOM 也能解析)。
---
## 4. 可引用的模块清单(无需写版本号)
| 分类 | artifactId(前缀均为 `reliable.simple.starter:`) |
| --- | --- |
| 基础 | `simple-starter-core` `simple-starter-json-jackson` `simple-starter-validation` `simple-starter-web` `simple-starter-doc` |
| 缓存 | `simple-starter-cache-redisson` `simple-starter-cache-jetcache` `simple-starter-cache-springcache` |
| 认证 | `simple-starter-auth-satoken` `simple-starter-auth-justauth` |
| 数据 | `simple-starter-data-core` `simple-starter-data-mp` |
| 加密 | `simple-starter-encrypt-api` `simple-starter-encrypt-core` `simple-starter-encrypt-field` `simple-starter-encrypt-password` |
| 验证码 | `simple-starter-captcha-graphic` `simple-starter-captcha-behavior` |
| 安全 | `simple-starter-security-xss` `simple-starter-security-mask` `simple-starter-security-sensitive` `simple-starter-security-idempotent` `simple-starter-security-ratelimiter` |
| 日志 | `simple-starter-log-core` `simple-starter-log-aop` `simple-starter-log-interceptor` `simple-starter-log-engine` |
| 消息 | `simple-starter-messaging-mail` `simple-starter-messaging-sse` `simple-starter-messaging-ws` `simple-starter-messaging-mqtt` |
| 文件 | `simple-starter-storage` |
| Excel | `simple-starter-excel-core` `simple-starter-excel-poi` `simple-starter-excel-fesod` |
| 增强 | `simple-starter-enhance-crud-core` `simple-starter-enhance-crud-mp` `simple-starter-enhance-datapermission-core` `simple-starter-enhance-datapermission-mp` `simple-starter-enhance-tenant-core` `simple-starter-enhance-tenant-mp` |
| 集群/任务/监控 | `simple-starter-cluster-grpc` `simple-starter-cluster-http-registry` `simple-starter-job-core` `simple-starter-metrics` `simple-starter-trace` `simple-starter-network` |
> 完整且权威的清单以 `simple-starter-bom` 的 `dependencyManagement` 为准。
---
## 5. 快照版(仅供联调,禁止进生产)
如需试用未定稿版本:
```xml
<version>2.6.4-SNAPSHOT</version>
```
同时把仓库的 `<snapshots><enabled>true</enabled></snapshots>` 打开,并强制刷新:
```bash
mvn -U clean package
```
`-U` 是必须的:Maven 对 SNAPSHOT 默认每天只检查一次更新,不加会拿到旧包。
---
## 6. 验证是否接通
```bash
mvn -U dependency:tree | grep simple-starter
```
能看到 `reliable.simple.starter:simple-starter-xxx:jar:2.6.4:compile` 及其传递依赖(Spring Boot 4.1.2、Hutool 5.8.48 等)就说明配置正确。
---
## 7. 常见问题
| 现象 | 原因与解决 |
| --- | --- |
| `401 Unauthorized` | 没配 `<server>`;或 `<server><id>` 与仓库 id `repo-mtndz` 不一致;或密码过期 |
| 命令能拉、IDE 报红 | IDEA 没 Override 指向同一份 `settings.xml`(见第 1 节) |
| `Could not find artifact` | ① 仓库地址没配或被 mirror 拦截;② 版本号写错(SNAPSHOT 与正式版是两个坐标) |
| mirror 导致拉不到 | `settings.xml` 中 `<mirrorOf>` 若含 `*`,必须排除本仓库:`*,!repo-mtndz` |
| 依赖版本冲突 | BOM 内置 `spring-boot-dependencies:4.1.2`,业务项目须使用 Spring Boot 4.1.x;若使用 3.x,会互相覆盖 |
| Web 模块容器冲突 | `simple-starter-web` 排除了 Tomcat 并引入 Jetty,业务项目若用 Tomcat 需先确认容器选型 |
| 拉到旧快照 | 加 `-U`;或在 `~/.m2/repository/reliable/simple/starter/` 下删掉对应版本目录 |
| `Non-resolvable parent POM` | 父 POM 未部署或权限不足;确认云效包列表里存在 `simple-starter`、`simple-starter-dependencies` |
---
## 8. 版本纪律
- **生产依赖只写正式版**(如 `2.6.4`),禁止 `-SNAPSHOT` 进生产或主干分支
- 正式版发布后内容**永不改动**;有问题就发下一个版本
- 快照可反复覆盖,仅用于联调阶段