@shundoo-ai/dsh-cosmic 1.0.4-alpha.5 → 1.0.4-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shundoo-ai/dsh-cosmic",
3
- "version": "1.0.4-alpha.5",
3
+ "version": "1.0.4-alpha.7",
4
4
  "description": "苍穹助手 bundle:金蝶云苍穹 ERP 的开发与数据分析(ERP 登录与取数、元数据建模、插件开发与热部署、可视化报告)。",
5
5
  "keywords": [
6
6
  "dsh",
@@ -53,6 +53,8 @@ description: >
53
53
  pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1 -Module <模块名>
54
54
  # 干净重建 + 热部署
55
55
  pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1 -Module <模块名> -Clean
56
+ # ⭐ 真编译 + 热部署(禁构建缓存 + 强制重跑,保证 javac 真的跑)
57
+ pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1 -Module <模块名> -Clean -NoCache
56
58
  # 只热部署已有 jar
57
59
  pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1 -Jar <jar路径>
58
60
  # 只构建、不部署
@@ -69,7 +71,7 @@ pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1
69
71
 
70
72
  内部依次完成:定位工作区 → 解析 preset bundle → 读 `dev.json` → **按端口反查 cosmic PID**(不是 `jps`,见职责②)→ 挑含 `tools.jar` 的 JDK → 构建 → Attacher 热加载。
71
73
 
72
- 参数:`-Module`|`-Jar`|`-Clean`|`-WhatIf`|`-LogFile`|`-Workspace`|`-PresetDir`|`-Port`。
74
+ 参数:`-Module`|`-Jar`|`-Clean`|`-NoCache`|`-WhatIf`|`-LogFile`|`-Workspace`|`-PresetDir`|`-Port`。
73
75
  工作区默认从「脚本位置的上两级」或当前目录推断;布局不同就传 `-Workspace <项目根>`。
74
76
 
75
77
  ---
@@ -187,16 +189,21 @@ cd <cwd>
187
189
  VER=$(grep -oE 'gradle-[0-9.]+-bin' gradle/wrapper/gradle-wrapper.properties | head -1 | sed 's/gradle-//;s/-bin//')
188
190
  GRADLE=$(find ~/.gradle/wrapper/dists/gradle-$VER-bin -type f -path '*/bin/gradle' 2>/dev/null | head -1)
189
191
  GRADLE_USER_HOME=<cwd>/.gradle/user-home "$GRADLE" :<模块>:build -x test
192
+ # 真编译(验证工具链 / 排除缓存欺骗):加 --no-build-cache --rerun-tasks
193
+ GRADLE_USER_HOME=<cwd>/.gradle/user-home "$GRADLE" :<模块>:clean :<模块>:build -x test --no-build-cache --rerun-tasks
190
194
  ```
191
195
 
192
- - 增量构建(内容感知:改几行代码约 5-10 秒,无改动约 1 秒);要绝对干净才加 `clean`。
196
+ - 增量构建(内容感知:改几行代码约 5-10 秒,无改动约 1 秒)。
197
+ - ⚠️ **`clean` 也不等于真编译**(平台中立):本模板 `gradle.properties` 带 `org.gradle.caching=true`,`clean` 后 `compileJava` 会直接 `FROM-CACHE` 还原 class(macOS 实测 **879ms**、Windows 实测约 **2 秒** 即跑完,javac 一次未调用)。**要真编译必须加 `--no-build-cache`**(对应 Windows 脚本的 `-NoCache`,逻辑同源)。
198
+ - ⚠️ **「伪成功构建」陷阱**(平台中立):`compileJava` 处于 `UP-TO-DATE` 时 Gradle **根本不加载编译器**,缺 tools.jar 也不报错 → 看到 `BUILD SUCCESSFUL` + jar 正常产出,**但里面是旧字节码**。首次接入务必用上面的真编译命令验证一次。
199
+ - **真编译判据(三条同时看)**:① Gradle 输出里 `compileJava` 后面**没有** `UP-TO-DATE` / `FROM-CACHE`;② stderr 出现 javac 的 `deprecation` / `unchecked` 提示;③ `build/classes` 下 class 的 mtime 是**刚刚**(旧字节码的特征是 class 时间戳停留在上一次真编译的时刻)。
193
200
  - 产物在 `<模块>/build/libs/*.jar`(本环境 `code/yun/sd-khxty-yun/build/libs/sd-khxty-yun-1.0.0.jar`)。
194
201
  - ⚠️ 产 jar **只认 gradle 命令行**:IDEA MCP `build_project` 默认增量、源码未变会跳过(`isSuccess:true` 但 jar 不更新);勿用 `buildJar`/`deployJar`(那是冷启动拷贝到 lib/cus,热部署不需要)。
195
202
 
196
203
  > **Windows 必读(实测踩坑,失败一次排查很久)**
197
204
  > - **必须显式设 `JAVA_HOME` 指向 JDK(不是 JRE)**:Windows 注册表 `HKLM\SOFTWARE\JavaSoft\Java Development Kit` 的 `JavaHome` 会被 JRE 安装包改写成 `...\jre1.8.0_481`,Gradle 采信它 → `java.home` 指向 JRE → 报 `Could not find tools.jar`。显式 `$env:JAVA_HOME="C:\Program Files\Java\jdk1.8.0_XXX"`
198
205
  > - **Gradle 版本必须按 `gradle/wrapper/gradle-wrapper.properties` 锁定**,不要「取 `~/.gradle/wrapper/dists` 下最新」—— 机器上可能同时装了要求 Java 22 的新版 Gradle,会直接把构建带偏。
199
- > - ⚠️ **「伪成功构建」陷阱**:`compileJava` 处于 `UP-TO-DATE` 时 Gradle **根本不加载编译器**,缺 tools.jar 也不报错 → 看到 `BUILD SUCCESSFUL` + jar 正常产出,**但里面是旧字节码**。首次接入务必 `clean build` 验证一次真编译。
206
+ > - ⚠️ **缓存会掩盖工具链问题**:`UP-TO-DATE`(`clean` 后则直接 `FROM-CACHE`)时 Gradle 根本不加载编译器,缺 tools.jar 也不报错 → 首次接入务必用职责③的真编译命令验证一次;Windows 脚本对应 `-NoCache`。
200
207
  >
201
208
  > 完整分析见 `cosmic-dev-best-practices/references/cosmic-hotdeploy-build-slow-windows.md` §4.3 / §4.7。Windows 上直接用上面「Windows:一条命令走完全程」的封装脚本即可,它已内置这些约束。
202
209
 
@@ -239,7 +246,7 @@ agent(`kd.reloadjar.ReloadAgent`)在 cosmic 进程内自动执行这两步
239
246
  4. **Attacher 必须和目标进程同 JDK 大版本**:`java_home` 以 IDEA 项目 SDK 为准,且必须与 cosmic 进程的 JDK 大版本一致(本环境 cosmic 是 JDK8,故 `java_home` 也是 JDK8,带 `tools.jar`)。跨版本 attach(如 JDK17 attach JDK8)会报 `AgentLoadException`。
240
247
  5. **agent 类名 + jar 路径被 JVM 缓存**:改 agent 代码后要么重启 cosmic,要么换新类名 + 新 jar 名。
241
248
  6. **accountId / tenantId 必填**:ExtClassLoader 按数据中心隔离,DB 访问要 RequestContext。
242
- 7. **构建**:日常用增量 `build`(Gradle 内容感知,删源文件也会清 stale class);要绝对干净才 `clean build`。
249
+ 7. **构建**:日常用增量 `build`(Gradle 内容感知,删源文件也会清 stale class);要**真编译**(验证工具链、排除 `UP-TO-DATE` / `FROM-CACHE` 两类缓存欺骗)用 `-Clean -NoCache`(macOS/Linux 对应 `clean build --no-build-cache --rerun-tasks`,见职责③)。
243
250
  8. **热部署 vs 冷启动**:热部署只影响当前运行会话(写 `t_meta_ext_jar`);重启后 `lib/cus` 由 `kd-appstore-download` 从 `apppackage-cosmic` 重新拉取。
244
251
 
245
252
  ---
@@ -250,5 +257,5 @@ agent(`kd.reloadjar.ReloadAgent`)在 cosmic 进程内自动执行这两步
250
257
  |------|------|------|
251
258
  | `assets/dev.json` | ① 开启热部署 | 空配置模板(`dev.py` 读它作字段基础,生成工作区 `.dsh/cosmic/config/dev.json`) |
252
259
  | `scripts/dev.py` | ① 开启热部署 | 环境配置脚本(`init`=读 `.kd/config.json` 覆盖 dev.json;`read`=只读;`__file__` 反推 skill 根) |
253
- | `scripts/cosmic-hotdeploy.ps1` | ②③ 热加载 / 构建+热部署 | **Windows 一键封装**(可移植:工作区自动推断、无硬编码路径):体检 / `-Module` 构建+热部署 / `-Clean` / `-Jar` 直传 / `-WhatIf`。见「Windows:一条命令走完全程」 |
260
+ | `scripts/cosmic-hotdeploy.ps1` | ②③ 热加载 / 构建+热部署 | **Windows 一键封装**(可移植:工作区自动推断、无硬编码路径):体检 / `-Module` 构建+热部署 / `-Clean` / `-NoCache`(真编译:`--no-build-cache --rerun-tasks`)/ `-Jar` 直传 / `-WhatIf`。见「Windows:一条命令走完全程」 |
254
261
  | `assets/kd-reloadjar-agent.jar` | ② 热加载 | 热重载 agent(含 `kd.reloadjar.ReloadAgent` + `Attacher`)。⚠️ **原件不要直接加载** —— 先复制到 `$DSH_HOME/cache/cosmic/agent/kd-reloadjar-agent-<sha1前8位>.jar` 再用(避免 preset 升级时被 JVM 锁住,见职责②§3) |
@@ -10,6 +10,7 @@
10
10
  # pwsh -File cosmic-hotdeploy.ps1 # health check only
11
11
  # pwsh -File cosmic-hotdeploy.ps1 -Module <name> # build + hot-deploy
12
12
  # pwsh -File cosmic-hotdeploy.ps1 -Module <name> -Clean # clean build + hot-deploy
13
+ # pwsh -File cosmic-hotdeploy.ps1 -Module <name> -Clean -NoCache # REAL javac rebuild (no cache, no up-to-date)
13
14
  # pwsh -File cosmic-hotdeploy.ps1 -Jar a.jar,b.jar # hot-deploy existing jars
14
15
  # pwsh -File cosmic-hotdeploy.ps1 -Module <name> -WhatIf # dry run (build only)
15
16
  #
@@ -29,6 +30,7 @@ param(
29
30
  [string[]]$Jar,
30
31
  [string]$Module,
31
32
  [switch]$Clean,
33
+ [switch]$NoCache,
32
34
  [switch]$WhatIf,
33
35
  [string]$LogFile,
34
36
  [string]$Workspace,
@@ -223,7 +225,15 @@ if ($Module) {
223
225
  if ($Clean) { $gradleArgs += (':' + $Module + ':clean') }
224
226
  $gradleArgs += (':' + $Module + ':build')
225
227
  $gradleArgs += @('-x', 'test', '--console=plain')
228
+ # -NoCache: '--no-build-cache' stops the local build cache from restoring compileJava FROM-CACHE
229
+ # (this template's gradle.properties sets org.gradle.caching=true, so a plain -Clean rebuild can
230
+ # finish in ~2s without ever invoking javac), and '--rerun-tasks' defeats UP-TO-DATE, so javac
231
+ # really runs even when -Clean is not given.
232
+ if ($NoCache) { $gradleArgs += @('--no-build-cache', '--rerun-tasks') }
226
233
  Write-Host "[build] gradle $distVer | $($gradleArgs -join ' ')"
234
+ if ($Clean -and -not $NoCache) {
235
+ Write-Host '[build] NOTE: -Clean alone can still restore classes FROM-CACHE (org.gradle.caching=true). Add -NoCache for a real javac run.'
236
+ }
227
237
  Write-Host "[build] JAVA_HOME=$buildJdk (GRADLE_USER_HOME=$gradleHome)"
228
238
  $env:GRADLE_USER_HOME = $gradleHome
229
239
  $env:JAVA_HOME = $buildJdk