Skip to content

feat(maven): Spring Boot 和 Java 应用出现在运行配置里,可运行、可调试 - #28

Merged
1lck merged 5 commits into
mainfrom
feat/run-spring-boot-services
Nov 17, 2026
Merged

1lck merged 5 commits into
mainfrom
feat/run-spring-boot-services

Conversation

@1lck

@1lck 1lck commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

关联 Issue / Linked issue

Refs 1lck/Lithe-IDEA#2074(Maven / Spring Boot 项目的标题栏下拉里没有运行配置)。宿主配套 1lck/Lithe-IDEA#2102:没有运行配置时说明原因,把宿主解析出的 Maven 路径作为 tool.executable 发给本插件的提供者,并修好真实端到端测试暴露的 4 个宿主缺陷(依赖树按 dependencies.source 读取、命令模型的设置页、未命名运行项的名称、运行准备期间的编译输出)。

PR 类型 / Type

  • feat

改动说明 / What changes

根因:插件以前只声明了模型、任务、测试和依赖,没有 buildSystems[].run,模型里也没有 target,所以 Core 生成不出任何运行配置,下拉一直是“没有运行配置”。本 PR 只用 Core 现有契约(buildProviders 0、provider run、lithe/build/prepareRun、注册表连接调试),不改宿主或 Core。

1. 模型里导出可运行的应用(extension/.../Applications.java、ModelExport)

来源 target 标签 名称 mainClass
编译源码根里带 @SpringBootApplication 的顶层 Java 类(每个一条,和 IDEA 一样) spring-boot 类的简单名,同名冲突时用全名 这个类
没有这种类但用了 spring-boot-maven-plugin 的模块(Kotlin、生成代码) spring-boot artifactId 插件 mainClass 或 start-class,都没有就留空
exec-maven-plugin 的 mainClass 或 maven-jar-plugin 的 archive/manifest/mainClass java-application 类的简单名 配置的类

只读源码开头 64 KiB(去掉注释后匹配注解)和 POM 配置,每个项目最多 20 000 个文件,不编译,读取模型仍然不生成 target/。${…} 没解析出来的值不当作类名。

2. 运行准备导出(extension/.../RunExport.java、LitheLifecycleParticipant.afterSessionEnd)

带 -Dlithe.runOutput / -Dlithe.runProject 时,扩展在构建结束后写出:运行时类路径(模块输出目录 + compile/runtime/system 依赖,用 ProjectDependenciesResolver 解析;反应堆兄弟模块用各自的 target/classes,不需要 install)和编译出的主类(读 class 文件常量池和方法表,找 public static void main(String[]),标出带 @SpringBootApplication 的类,最多读 50 000 个 class 文件)。构建失败时不写。project(session, path) 从 DependencyExport 移到 ModelExport 共用。

3. 构建提供者(provider/,打包为 lib/lithe-maven-provider.jar)

用随仓库的 Java SDK、按 Java 8 编译,只处理 lithe/build/prepareRun:

  1. Maven 程序取宿主发来的 tool.executable(即用户设置的 Maven executable),没有时按 mvnw → MAVEN_HOME → mvn 查找。没有目录的命令名在启动前按 PATH 解析,Windows 上按 PATHEXT 补扩展名:Java 在 Windows 上直接启动裸命令名时只认 .exe,mvn(实为 mvn.cmd)会启动失败并被报成“插件后端意外失败”——这是本 PR 先前 Windows CI(runner Maven 那一格)失败的原因。找不到时报 maven.run.noMaven,提示安装或填写完整路径。
  2. 在实例根目录运行 mvn -B -ntp <构建选项参数> -Dmaven.ext.class.path=<包内扩展> -Dlithe.runOutput=<临时文件> -Dlithe.runProject=./<模块> -pl ./<模块> -am process-classes;环境变量是进程环境加构建选项(如 JAVA_HOME)。输出按 64 KiB 分块作为进度流到运行窗口,取消时由 SDK 结束整个进程树。
  3. 主类依次取:运行配置的入口(launchOptions.entrypoint)→ target 的 mainClass → 编译结果里唯一的主类(Spring Boot target 优先带注解的类)。没有或有多个时报错,错误里列出候选,并提示在运行配置的“入口”里填。
  4. 返回 {executable: toolchain java, arguments: JVM 参数 + -cp <类路径> + 主类 + 程序参数 + 用户参数, workingDirectory: 配置的目录或模块路径, environment: 配置的环境变量},由 Lithe 用项目的 JDK 启动并管理进程。不经过 spring-boot:run,Lithe 停止的就是应用本身。
  5. 类路径超过 24 000 个字符时写进 target/lithe-run/classpath-<哈希>.jar(只含清单,和 IDEA 的 “JAR manifest” 缩短方式一样),避开 Windows 32 767 字符的命令行上限;这是构建输出,mvn clean 会删,相同类路径复用同一个 jar,先写临时文件再原子改名。
  6. 调试(宿主尚未接线,见 [Feature] 构建提供者的服务运行支持按配置类型连接调试(Spring Boot 运行配置可直接点调试) 1lck/Lithe-IDEA#2107):请求带 launchOptions.debug 的连接目标时,在 -cp 前加 -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=<host>:<port>,服务停在启动处,等宿主选中的 Java 调试器连上;目标不是合法的本地端口时拒绝。
  7. 失败提示按 initialize 的 locale 选中文或英文(Messages)。

4. plugin.json

  • requires 加 buildProviders: 0,权限加 languageServer.launch(契约要求提供者进程持有这项权限)。
  • buildSystems[0].provider:runtime / java ≥ 8 / lib/lithe-maven-provider.jar / -Xms16m -Xmx96m,executesProjectCode、mayUseNetwork 都为 true(编译会执行 POM 里的插件、可能下载依赖),Lithe 会先确认工作区可信。
  • buildSystems[0].run:spring-boot(fromTargets.tags: [spring-boot],execution: service,debug.configurationType: java)和 application(fromTargets.tags: [java-application],execution: application)。

5. 打包:scripts/package.mjs 把两个 javac 构建的进程合成同一个 backendJar(),产出 lib/lithe-maven-settings.jar 和 lib/lithe-maven-provider.jar;.gitignore 加 provider/target/。

6. 测试夹具与集成测试

  • 夹具新增 service 模块:依赖 core,带一个本地的 SpringBootApplication 替身注解(不联网下载 Spring),ServiceApplication 输出 JVM 属性、参数和环境变量。app 的 jar 清单写明 demo.app.Main。
  • scripts/test.mjs 新增:target 列表与 run 声明一致;启动打包后的提供者,对 service 准备运行并真正执行返回的命令,检查输出里的 -Dgreeting=hi there、--port=0,typed 和 LITHE_FIXTURE=set,类路径首项是 service/target/classes、含反应堆兄弟模块 core/target/classes、不含 junit;app 不给 mainClass 时用编译出的唯一主类并运行;调试参数在 -cp 之前;制造编译错误后准备失败且报出提供者的错误;Maven 命令不在 PATH 上时报 maven.run.noMaven。
  • README 新增“运行应用”一节,功能矩阵新增 maven-run-applications(运行 implemented;调试标为待宿主支持 #2107,验证 pending)。

7. 宿主端到端测试(e2e/host/)

  • 新增 official_maven_plugin_run_e2e_test.go 的 TestOfficialMavenPluginRunsASpringBootApplication:在真实 Spring Boot 3.5.13 双模块工程(common 库 + web 应用)里装上本插件和 Java Support 发行包,检查下拉只有 ShopApplication、执行方式是 service;在运行配置编辑器里保存 JVM 参数 -Dshop.name=Lithe、程序参数(端口、地址)和环境变量 SHOP_REGION=eu-west;启动后请求 /hello 必须返回 Hello, Lithe from eu-west,控制台有 BUILD SUCCESS、common 模块编译、Tomcat started on port N、Started ShopApplication;停止后端口释放、接口不再应答,插件包内容不变。
  • official_maven_plugin_e2e_test.go:安装辅助函数像 app.go 一样接上工具解析器,支持把多个插件装进同一个服务;读取运行控制台改用 op.session.output.all()。
  • lithe-host.json 的宿主版本升到包含 #2102 的 main 提交,用例正则加上新用例,requiredEnvironment 加 LITHE_TEST_JAVA_PLUGIN_ARCHIVE(Java Support 提供启动计划要用的 java 工具);README 写明取得发行包的 gh release download 命令。

版本:本 PR 不改版本号。插件新增了 requires.buildProviders,按 #27 的做法发版时升主版本(2.0.0)。现在的正式桌面版 desktop-v0.8.3 已声明 buildProviders 0。

范围检查 / Scope checks

  • 插件代码、测试、功能矩阵、文案只在本仓库;不往宿主或 Core 加 Maven 知识。宿主侧唯一配套改动(发送已有的可选字段 tool.executable)是通用的,在 fix(desktop): 没有运行配置时说明原因,“编辑运行配置…”不再无反应 1lck/Lithe-IDEA#2102。
  • 不维护第二份模型:类路径和依赖由用户的 Maven 和 ProjectDependenciesResolver 解析,主类来自真实编译结果。
  • 运行时只读插件目录:提供者从包里读扩展 jar;运行文档写在系统临时目录、用完删除;类路径 jar 写在项目的 target/ 下。
  • 子进程有取消和整树清理(SDK CallContext.run),测试里每次等待都有上限,失败时结束提供者进程组。
  • 失败路径给出明确错误码:maven.run.buildFailed、noMaven、noRunDocument、noMainClass、ambiguousMainClass、invalidDebug、invalidProject、noWorkspace。
  • 没有新增设置;构建选项(JDK、Profiles、Settings File、Local Repository、Offline、Skip Tests)原样作用于运行前的编译。
  • 没有提交产物或私人路径。

验证 / Verification

命令或操作 平台 结果
node scripts/package.mjs macOS arm64 成功,包里有三个 jar
MAVEN_ARGS="-s <去掉 profiles 的 settings 副本>" node scripts/test.mjs(含 PATH 解析修复之后重跑) macOS arm64 全部通过(含 10 项新的 target / 运行准备检查)
不隔离 settings 直接运行 node scripts/test.mjs macOS arm64 只有 Profiles 一项失败,多出的 ali、nexus 来自本机 ~/.m2/settings.xml,与本改动无关;运行准备相关检查全部通过
用 Lithe-IDEA 当前 Core 校验新的 plugin.json(pluginhost.Validate + 宿主 Declared() 能力,临时测试) macOS arm64 接受

| node scripts/e2e-host.mjs(宿主固定到 75edb9674,即合入 #2102 的 main;本 PR 的 dist/maven-build-1.0.0-darwin.zip + Java Support 4.0.1 darwin-arm64,真实 mvn) | macOS arm64 | TestOfficialMavenPluginBuildsAReactor PASS(47.8s)、TestOfficialMavenPluginRunsASpringBootApplication PASS(6.0s,PATH 解析修复后重新打包再跑)、TestMavenPluginProjectGeneratesABuildableMavenProject PASS;TestMavenPluginArchetypeRunsRealMaven 按设计在未设 LITHE_INTEGRATION_NETWORK 时跳过。结束后没有 java / 测试进程残留 |

| GitHub Actions:Linux(runner / 3.6.3 × x64 / arm64)和 Windows(runner / 3.6.3) | Linux、Windows | 4e565b6 全部通过(run 44088348161);06e8732 上 windows (runner) 的“prepare ServiceApplication”失败由 PATH 解析修复 |

未能执行的检查:调试要等宿主 #2107;Windows 只有 CI 的 scripts/test.mjs,没有在 Windows 上跑宿主端到端;功能矩阵的验证状态都是 pending,手工验收步骤写在 docs/feature-matrix.md。

🤖 Generated with Claude Code

1lck and others added 3 commits November 17, 2026 04:04
The model now lists Spring Boot applications (@SpringBootApplication
classes, or spring-boot-maven-plugin) and applications whose main class
exec-maven-plugin or the jar manifest names as targets tagged
spring-boot / java-application with a mainClass property. Reading stays
compile-free: only source heads and POM configuration are read, within
fixed bounds.

With -Dlithe.runOutput and -Dlithe.runProject the extension writes, after
the build, the project's runtime classpath (output folder plus compile,
runtime and system dependencies, reactor siblings from their output
folders) and the compiled classes with a main method, marking the
@SpringBootApplication ones. A failed build writes nothing.

Refs 1lck/Lithe-IDEA#2074

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
plugin.json declares a build provider process (lib/lithe-maven-provider.jar,
built with the vendored Java SDK for Java 8) and two provider runs:
spring-boot (service, debuggable through a registry java adapter) and
application. prepareRun compiles the project with -pl -am process-classes
using the Maven Lithe resolved (or mvnw, MAVEN_HOME, PATH), reads the run
document the extension wrote and returns java -cp <classpath> <main class>
on the project's JDK. Long classpaths go into a manifest-only jar under
target/lithe-run/. A debug request adds a suspending JDWP agent on the
host's port.

Refs 1lck/Lithe-IDEA#2074

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… runs

The fixture gains a Spring Boot service module (a local stand-in for the
annotation, no download) and a jar-manifest main class in app. The
integration lane checks the targets, then starts the packaged provider,
prepares runs and launches the returned commands, and checks the reactor
classpath, main class discovery, debug arguments and a failed build.

README and the feature matrix describe the new maven-run-applications
capability.

Refs 1lck/Lithe-IDEA#2074

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1lck and others added 2 commits November 17, 2026 04:55
…ost that supports it

- TestOfficialMavenPluginRunsASpringBootApplication installs the Maven and Java Support
  archives, saves JVM/program arguments and an environment variable in the run
  configuration editor, runs ShopApplication, checks /hello and the console, then stops it.
- The archive helper wires the tool resolvers like the app and can install several plugins
  into one service; run console output is read from the operation's session.
- lithe-host.json pins 75edb9674 (1lck/Lithe-IDEA#2102) and requires
  LITHE_TEST_JAVA_PLUGIN_ARCHIVE.
- README and feature matrix: debugging waits for host support (1lck/Lithe-IDEA#2107).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dows

Java starts a command without a directory through the operating system, which on Windows
finds only .exe files, so `mvn` (mvn.cmd there) failed to start and the preparation ended
as "The plugin backend failed unexpectedly". The provider now resolves such a name on the
PATH of the build environment, trying each PATHEXT extension on Windows, and reports
maven.run.noMaven when nothing matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@1lck
1lck marked this pull request as ready for review November 17, 2026 13:03
@1lck
1lck merged commit 5774848 into main Nov 17, 2026
7 of 11 checks passed
@1lck 1lck changed the title feat(maven): Spring Boot 和 Java 应用出现在运行配置里,可运行、可调试 feat(maven): Spring Boot 和 Java 应用出现在运行配置里,可运行(调试待宿主 #2107) Nov 17, 2026
@1lck 1lck changed the title feat(maven): Spring Boot 和 Java 应用出现在运行配置里,可运行(调试待宿主 #2107) feat(maven): Spring Boot 和 Java 应用出现在运行配置里,可运行、可调试 Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant