Skip to content

fix(windows): Maven compile uses project/Maven JDK instead of env JDK (#1216) - #1537

Closed
lithe-claude-coding[bot] wants to merge 2 commits into
previewfrom
bot/issue-1216-maven-jdk
Closed

lithe-claude-coding[bot] wants to merge 2 commits into
previewfrom
bot/issue-1216-maven-jdk

Conversation

@lithe-claude-coding

Copy link
Copy Markdown

Fixes #1216.

Source Issue

#1216: Windows Maven sidebar compile uses the machine env JDK (reporter: env JDK 1.8) instead of the configured project/Maven JDK (21).

Root cause (brief)

The TypeScript Maven launch layer resolves a Maven JDK (Maven setting -> Run Maven JDK -> Run project JDK), but windows/tauri/src-tauri/src/run.rs run_resolve_launch then kept the automatic JDK in JAVA_HOME via entry().or_insert(). A resolved automatic JDK therefore silently shadowed a configured Maven JDK. The automatic JDK itself also prefers env JAVA_HOME, which is why 1.8 won.

Minimal fix

  • windows/tauri/src-tauri/src/run.rs run_resolve_launch: for a Maven launch with an explicitly configured Maven JDK, the resolved Maven JDK now overwrites JAVA_HOME. With no Maven JDK configured, the previous precedence is unchanged (explicit environment JAVA_HOME, then automatic/project JDK, then inherited env).
  • No change to the generic non-Maven Run path, no global reordering of automatic JDK priority, no pom release/source reading into select_java.
  • Added Rust regression test maven_launch_uses_configured_maven_jdk_over_automatic_jdk: automatic JDK 1.8 + Maven JDK 21 -> JAVA_HOME is 21; Maven JDK empty -> JAVA_HOME is the automatic/project JDK.
  • Matrix: added windows/tauri/src-tauri/src/run.rs to the Windows evidence of java-maven-project-settings (implementation already implemented, verification remains pending). The mocked TypeScript test maven-project-jdk.test.ts is NOT cited as coverage for this Rust change.

Linux code-level verification done

  • git diff is only the two intended files above, no secrets, no unrelated changes, no media files.
  • ./scripts/verify-platform-feature-matrix-change.sh origin/preview HEAD: passed.
  • ./scripts/verify-platform-feature-matrix.sh: passed, 209 capabilities validated.
  • ./.agents/skills/write-stable-tests/scripts/verify-test-stability.sh: passed.
  • cargo fmt --check and the new Rust test could NOT be run on this Linux VM: cargo/rustc, Java, and Maven are not installed here, and the Tauri host crate is a Windows test target (cargo test --manifest-path windows/tauri/src-tauri/Cargo.toml on Windows). Do not treat those as passed; CI / a Windows runner must run them.

Not verified on a real Windows machine

This PR is NOT verified on a real Windows machine. Still needed on Windows before merge:

  • Project with env JAVA_HOME 1.8 + project/Maven JDK 21, click compile in the right Maven sidebar, confirm build output / mvn -version reports JDK 21 and compilation succeeds against 21 APIs.
  • No-Maven-JDK case still uses the project JDK.
  • mvnw projects and multi-module -pl/-am goals are unaffected.
  • Note: if a configured Maven JDK path is invalid, resolve_java_home now fails the launch with a clear message instead of silently compiling under 1.8; call that out in review.

Draft PR only, do not merge, do not mark ready until Windows verification and CI Rust tests pass.

…#1216)

Windows Maven sidebar compile resolved a Maven JDK (Maven setting, Run Maven JDK, or Run project JDK) but run_resolve_launch then kept the automatic JDK in JAVA_HOME via or_insert, so an env JDK 1.8 silently shadowed a configured JDK 21. For a Maven launch with an explicitly configured Maven JDK, the resolved Maven JDK now overwrites JAVA_HOME; with no Maven JDK configured, the previous precedence is unchanged. Adds a Rust regression test for both cases. Windows real-machine verification is pending.
@ghfind-review ghfind-review Bot added the review: no-score ghfind author score missing (not zero) label Oct 27, 2026
@lithe-claude-coding
lithe-claude-coding Bot marked this pull request as ready for review October 27, 2026 11:28
@lithe-code-review

lithe-code-review Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Lithe Review

结论: ⛔ 有阻塞
范围: preview ← bot/issue-1216-maven-jdk · head: 776ec8f

Findings

  1. [P1] 将 Maven JDK 覆盖限制在当前 Maven 进程内
    windows/tauri/src-tauri/src/run.rs:711

    • 实际影响:新增分支只检查 Maven JDK 路径是否非空,会把普通 Run 的 JAVA_HOME 也覆盖为 Maven JDK。例如项目 JDK 为 21、Maven JDK 为 8 时,原本可运行的 Gradle 9 任务会改用 JDK 8,因不满足运行时版本要求而失败。
    • 触发条件:项目分别配置不同的 Java/Maven JDK,并启动需要项目 JDK 的非 Maven 任务。
    • 复现步骤:设置项目 JDK 21、Maven JDK 8,运行已检测到的 Gradle 9 application/service 配置。Core 的 apply_global_toolchain(rust/lithe-core/src/execution/configuration.rs:1260)会将 Maven JDK 默认值填入 Java 配置;run.store.ts:977 又通过 mavenProcessPaths 无条件传入该字段。因此本分支会把 Gradle 的环境从 JDK 21 改为 JDK 8。无需启动进程即可构造相同解析输入,检查返回的 JAVA_HOME。
    • 来源:本次引入。base 使用 or_insert,保留此前已写入的项目 JDK;head 使用无条件 insert,且未检查 args.executable。这也违背 PR 声明的“普通非 Maven Run 路径不变”。

Scope Check

  • 关联需求:[Bug]右侧maven栏,点击compile命令后,没有使用项目配置的jdk #1216 的 Maven 侧栏配置 JDK 被自动 JDK 遮蔽问题,静态调用链显示已得到修正。
  • 已完成范围:宿主优先级调整、新增两种 Maven 解析场景的 Rust 测试、矩阵证据更新。
  • 未完成范围:非 Maven 启动隔离存在上述回归;Windows 实际执行尚无验证证据。
  • 上游复用:沿用 Maven 和现有工具链解析,属于宿主环境编排,无新增并行领域实现。
  • Finding 为本次引入,属于此次公共启动解析器修改的直接影响范围。

Suggestions

  1. 按当前主任务或前置步骤的 executable 判断是否为 Maven,例如仅在 executable.toolchain == "project-maven" 时执行此覆盖。增加“项目 JDK 21、Maven JDK 8、非 Maven executable”的回归测试,确认项目 JDK及显式环境值保持原有优先级。不要仅按整个配置是否使用 Maven 判断,因为 Java 主进程与 Maven 前置步骤可共享配置。
  2. 补充 Windows Rust 测试及实际 Maven 工作流验证,覆盖侧栏 compile、继承项目 JDK、wrapper 和多模块执行。

Summary

修复命中了 Maven 侧栏的环境优先级问题,但将覆盖行为扩展到了所有启动类型,造成非 Maven 构建回归。新增测试具备失败时清理临时目录的机制,但未覆盖这条关键隔离边界。

Verification

  • 实际检查:指定 base…head 的两个文件全部差异,以及 Maven 侧栏 → host、Run 主任务/前置步骤 → host、Core 工具链默认值与 Gradle 启动计划的直接调用链;git diff --check 通过。
  • 已提供结果:作者报告两个矩阵检查和测试稳定性静态检查通过;未独立执行这些检查。
  • CI 上下文:Windows Rust、前端及真实 JDT 测试均为 skipped;Windows gate 成功不能作为这些测试通过的证据。
  • 本次未运行:任何仓库代码、测试、格式化检查、构建或应用;未访问网络。
  • 验证缺口:新增 Rust 测试未有执行结果,Windows 实际 Maven/Gradle 行为尚未验证,运行时 bundle 只读检查结果也未提供。

PR #1537 P1 review: run_resolve_launch previously overwrote JAVA_HOME
with a configured Maven JDK for every launch, so a non-Maven task
(project JDK 21, Maven JDK 8, e.g. Gradle 9) would silently run under
JDK 8. Gate the override on executable.toolchain == "project-maven".
Non-Maven launches keep project JDK and explicit environment priority.

Add regression test non_maven_launch_keeps_project_jdk_over_configured_maven_jdk:
project JDK 21 + Maven JDK 8 + project-jdk executable -> JAVA_HOME 21;
explicit environment JAVA_HOME still wins. Existing Maven cases unchanged:
Maven JDK 21 wins, Maven empty -> automatic/project JDK.

Windows real-machine verification still pending; Rust tests and cargo fmt
could not run on this Linux VM (no cargo/rustc) and must run in CI/Windows.
@lithe-claude-coding

Copy link
Copy Markdown
Author

P1 已修复(新提交 177ca61,仍在同一分支 bot/issue-1216-maven-jdk):

  • windows/tauri/src-tauri/src/run.rs 的 Maven JDK 覆盖现在只在当前启动是 Maven 时生效,即 executable.toolchain == "project-maven" 时才用 Maven JDK 覆盖 JAVA_HOME。非 Maven 启动(如 Gradle 任务)不再被 Maven JDK 覆盖,保持项目 JDK 和显式环境 JAVA_HOME 的原有优先级。
  • 新增回归测试 non_maven_launch_keeps_project_jdk_over_configured_maven_jdk:项目 JDK 21 + Maven JDK 8 + project-jdk 启动 -> JAVA_HOME 为 21;显式环境 JAVA_HOME 仍优先。原有 Maven 场景(Maven JDK 21 胜出、Maven 为空时用自动/项目 JDK)保持不变。

未宣称已通过的验证:本机 Linux VM 无 cargo/rustc,Rust 测试和 cargo fmt 未能在此运行,需 CI/Windows 运行;Windows 真机 Maven/Gradle 实际行为仍待验证,PR 仍为 open、未合并。

@1lck 1lck closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: no-score ghfind author score missing (not zero)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant