Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ extension/target/
.DS_Store
.cache/
settings-backend/target/
provider/target/
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
| 彩色输出 | 每条 Maven 命令都带 `-Dstyle.color=always`,即使输出不是终端也保留 Maven 的颜色;Lithe 的构建、运行和测试控制台按颜色显示 `[INFO]`、`[WARNING]`、`[ERROR]` 和 `BUILD SUCCESS`,匹配诊断前会先去掉颜色转义 |
| 依赖 | 显示整个反应堆或单个模块的依赖树(含作用域和传递依赖),反应堆内未安装的兄弟模块也能解析 |
| 同步 | `pom.xml`、`.mvn/maven.config`、`.mvn/extensions.xml` 变化后重新读取项目 |
| 运行配置 | Spring Boot 应用和写明主类的 Java 应用自动出现在标题栏的运行配置里,可以运行和编辑参数,见下面的「运行应用」 |

## 设置和构建选项

Expand Down Expand Up @@ -65,6 +66,8 @@ JDK 是构建选项而不是插件设置,因为契约 v0 的插件设置不能
3. 环境变量 `MAVEN_HOME` 下的 `bin/mvn`;
4. `PATH` 里的 `mvn`。

运行前的编译由构建提供者执行:它用 Lithe 按上面的顺序解析出的程序;只拿到命令名(例如 `mvn`)时,按 `PATH` 查找,Windows 上再按 `PATHEXT` 补扩展名(`mvn.cmd`),找不到时报 `maven.run.noMaven`。

要求 Maven 3.6.3 或更新版本、Java 8 或更新版本。没有 Maven 的话可以先安装:

```bash
Expand All @@ -83,11 +86,39 @@ brew install maven
选中模块时用 `-Dlithe.dependenciesProject` 只导出这个模块,否则导出反应堆里的每个模块。
- 输出文件由 Lithe 在这个工作区的插件状态目录(插件包之外的可写目录)里分配,Maven 退出后读取并删除。
- 读取项目和依赖不会编译或打包,也不会生成 `target/`;解析依赖时只读 POM,不下载依赖 jar。
- 准备运行时,扩展在构建结束后把类路径和主类写到 `-Dlithe.runOutput` 指定的临时文件(见「运行应用」),
构建失败时不写。
- 没有 Lithe 的属性时扩展什么都不做;插件目录在运行时保持只读。

读取项目会执行 POM 中声明的 Maven 扩展和插件,首次读取还可能联网下载插件描述,所以这两条命令都声明了
`executesProjectCode` 和 `mayUseNetwork`,Lithe 会先确认你信任这个工作区。

## 运行应用

读取项目时,扩展把能运行的应用列为构建模型里的 target,`plugin.json` 的 `run` 把它们变成运行配置:

| 运行配置 | 来源 | 执行方式 |
| --- | --- | --- |
| `spring-boot` | 源码根里带 `@SpringBootApplication` 的类(每个一条);没有这样的类但用了 `spring-boot-maven-plugin` 的模块(一条,主类取插件的 `mainClass` 或 `start-class`) | 服务 |
| `application` | `exec-maven-plugin` 的 `mainClass` 或 jar 清单 `archive/manifest/mainClass` 写明主类的模块 | 应用 |

列 target 只读源码开头和 POM,不编译。运行时 Lithe 启动随包的构建提供者 `lib/lithe-maven-provider.jar`
(源码在 `provider/`),由它准备运行:

1. 用你的 Maven(Lithe 解析出的那个,否则按 `mvnw`、`MAVEN_HOME`、`PATH` 查找)和当前构建选项运行
`-pl <模块> -am process-classes`,编译这个模块和它依赖的反应堆模块,输出显示在运行窗口。
2. 扩展在构建结束后写出运行时类路径(模块输出目录加 compile/runtime/system 依赖,兄弟模块用反应堆里的
`target/classes`,不需要 `install`)和编译出的主类。
3. 返回 `java -cp <类路径> <主类>`,由 Lithe 用项目的 JDK 启动并管理这个进程。主类依次取运行配置的入口、
target 的 `mainClass`、编译结果里唯一的主类(Spring Boot 优先带注解的类);有多个时报错并列出候选。
类路径超过 24 000 个字符时写进 `target/lithe-run/` 下只含清单的 jar,避开 Windows 命令行长度限制。
4. 清单为 Spring Boot 运行声明了按配置类型连接的调试(`debug.configurationType: java`):宿主带着调试端口请求时,
提供者加 `-agentlib:jdwp=…,suspend=y`,服务停在启动处等 Java 调试器连上。Lithe 桌面端还没有实现这段宿主流程
([1lck/Lithe-IDEA#2107](https://github.com/1lck/Lithe-IDEA/issues/2107)),目前点调试会提示这个配置不能调试。

不经过 `spring-boot:run`,Lithe 停止的就是应用进程本身。运行配置里的 JVM 参数、程序参数、环境变量和工作目录
原样带到启动命令。

## 安装

1. 从 [Releases](https://github.com/Lithe-IDEA/lithe-plugin-maven/releases) 下载对应平台的包:macOS 用
Expand Down Expand Up @@ -167,6 +198,10 @@ node scripts/verify-scripts.mjs --host-bundle /Applications/Lithe.app

- `TestOfficialMavenPluginBuildsAReactor`(宿主的 `desktop/internal/workbench` 包):读取两模块反应堆的模型和依赖树,
改 Maven executable 设置后重新读取并运行 `compile`,最后确认插件安装目录没有被写入。
- `TestOfficialMavenPluginRunsASpringBootApplication`(`desktop/internal/workbench` 包):和 Java Support 插件包一起安装,
打开一个真实的两模块 Spring Boot 3.5 项目(`spring-boot-starter-web`),确认运行配置下拉只列出 `ShopApplication`(服务),
用运行配置编辑器保存 JVM 参数、程序参数和环境变量,运行后检查控制台里的 Maven 构建日志和 Spring Boot 启动日志,
请求 `/hello` 确认三项设置都传到了进程;停止后确认服务不再响应、端口已释放,插件安装目录没有被写入。
- `TestMavenPluginProjectGeneratesABuildableMavenProject`、`TestMavenPluginArchetypeRunsRealMaven`(`desktop/internal/projectgen` 包):
用清单里的两个新建项目条目生成项目。

Expand All @@ -177,10 +212,15 @@ node scripts/verify-scripts.mjs --host-bundle /Applications/Lithe.app

```bash
node scripts/package.mjs
LITHE_TEST_MAVEN_PLUGIN_ARCHIVE="$PWD/dist/maven-build-<版本>-darwin.zip" node scripts/e2e-host.mjs
gh release download --repo Lithe-IDEA/lithe-plugin-java --pattern 'Lithe-Java-Support-*-darwin-arm64.zip' --dir .artifacts/java-plugin
LITHE_TEST_MAVEN_PLUGIN_ARCHIVE="$PWD/dist/maven-build-<版本>-darwin.zip" \
LITHE_TEST_JAVA_PLUGIN_ARCHIVE="$PWD/.artifacts/java-plugin/Lithe-Java-Support-<版本>-darwin-arm64.zip" \
node scripts/e2e-host.mjs
```

- `LITHE_TEST_MAVEN_PLUGIN_ARCHIVE` 必须设置,脚本不会因为缺少插件包而跳过测试。
- `LITHE_TEST_MAVEN_PLUGIN_ARCHIVE` 和 `LITHE_TEST_JAVA_PLUGIN_ARCHIVE` 都必须设置,脚本不会因为缺少插件包而跳过测试。
运行计划用 `java` 工具启动应用,这个工具由 Java Support 插件定义,所以运行测试要装上它。
- 运行测试使用本机 `~/.m2` 和 Maven 设置,第一次运行会下载 Spring Boot 3.5 的依赖,项目需要 JDK 17 及以上。
- 新建项目测试读取 `LITHE_PLUGIN_MAVEN_DIR` 里的 `plugin.json` 和模板,默认是本仓库的 `io.github.lithe-idea.maven-build/`。
- 原型测试要从 Maven Central 下载原型插件,只在设置了 `LITHE_INTEGRATION_NETWORK=1` 和 `JAVA_HOME` 时运行,否则跳过。

Expand Down
37 changes: 36 additions & 1 deletion docs/feature-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ CI 在 Windows x64 上用 `mvn.cmd` 运行声明的模型、依赖和测试命
| `java-maven-toolbar-tooltips` | 构建窗口里的 Maven 图标、工具栏开关和提示 | implemented / pending | implemented / pending | 没有自动化覆盖 |
| `maven-user-settings-editing` | 编辑用户级 `~/.m2/settings.xml` 的本地仓库 | missing / not-applicable | missing / not-applicable | — |
| `maven-project-generators` | 新建项目:Maven 和 Maven Archetype | implemented / pending | implemented / pending | 2026-11-14 宿主端到端测试通过(macOS) |
| `maven-run-applications` | 运行配置:Spring Boot 服务和 Java 应用的运行(调试待宿主支持) | implemented / pending | implemented / pending | 2026-11-17 宿主端到端测试和 `scripts/test.mjs` 通过(macOS);`scripts/test.mjs` 在 Windows CI 通过 |

前六条从主仓库迁移,最后一条是本仓库新增,用来记录随测试一起迁来的新建项目测试。
前六条从主仓库迁移;`maven-project-generators` 是本仓库新增,用来记录随测试一起迁来的新建项目测试;`maven-run-applications` 随运行配置一起新增([1lck/Lithe-IDEA#2074](https://github.com/1lck/Lithe-IDEA/issues/2074))。

## java-maven-project

Expand Down Expand Up @@ -195,3 +196,37 @@ ArtifactId);Maven Archetype 用内置或自定义原型,由 `mvn archetype

包里只有声明资源和纯 Java 的扩展 JAR,ARM64 与 x64 的差别只在用户自己的 JDK 和 Maven,所以 ARM64 用同一份包,
但在原生 ARM64 CI 或手工验收通过前不宣称通过。

## maven-run-applications

**能力**:读取项目时把 Spring Boot 应用(`@SpringBootApplication` 类或 `spring-boot-maven-plugin`)和写明主类的
Java 应用(`exec-maven-plugin`、jar 清单)列为 target,`run` 声明把它们变成运行配置;构建提供者
`lib/lithe-maven-provider.jar` 准备运行:编译模块及其反应堆依赖,导出运行时类路径和主类,返回 `java -cp … 主类`。
Spring Boot 运行声明了按配置类型连接的调试:宿主带调试端口请求时,提供者加 `-agentlib:jdwp` 挂起到调试器连上;Lithe 桌面端尚未实现这段宿主流程([1lck/Lithe-IDEA#2107](https://github.com/1lck/Lithe-IDEA/issues/2107)),所以调试目前不可用。

**证据**:`plugin.json` 的 `buildSystems[0].provider` 和 `buildSystems[0].run`、`extension/.../Applications.java`、
`extension/.../RunExport.java`、`provider/`、`scripts/test.mjs` 的运行准备检查、`test/fixtures/reactor/service/`。

**依赖的宿主能力**:`buildProviders`(独立提供者进程和 `lithe/build/prepareRun`)、运行配置解析(`fromTargets`)、
注册表连接调试(`debug.configurationType: java`,需要启用一个提供 `java` 类型 `attach` 的调试适配器)。

**最近验证**:2026-11-17,macOS arm64,插件 1.0.0 打包产物,宿主 `75edb9674`(合入 1lck/Lithe-IDEA#2102 的 main),`node scripts/e2e-host.mjs`:

- `TestOfficialMavenPluginRunsASpringBootApplication` PASS(6.2s):和 Java Support 4.0.1 发布包一起安装,打开真实的两模块
Spring Boot 3.5.13 项目;运行配置下拉只列出服务 `ShopApplication`;编辑器保存的 JVM 参数、程序参数和环境变量传到了进程
(`/hello` 返回 `Hello, Lithe from eu-west`);控制台有 Maven 构建日志(含兄弟模块 `common`)和 Spring Boot 启动日志;
停止后服务不再响应、端口释放;插件安装目录不变。同一轮 `TestOfficialMavenPluginBuildsAReactor` PASS。
- `node scripts/test.mjs`:提供者的运行准备、类路径、主类选择、调试参数和编译失败。

这次实测发现并在 #2102 修好了四个宿主问题:声明了提供者进程的构建系统读取写文件的依赖命令时缺少输出文件、设置页按提供者读取模型、
未命名的运行配置带上了运行 ID 前缀、准备运行时的构建输出没有显示。调试没有验收(宿主尚未支持,见上)。Windows 没有运行。

**验证方法**(macOS):

1. 安装插件包,打开含 Spring Boot 模块和 `exec-maven-plugin` 模块的多模块项目,信任工作区。
2. 标题栏运行配置菜单列出每个应用;选中 Spring Boot 应用点运行,运行窗口先显示 Maven 编译输出,再显示应用输出;
停止后应用进程退出。
3. 在运行配置编辑器里改 JVM 参数、程序参数、环境变量和入口,再次运行时生效。
4. 宿主支持后(1lck/Lithe-IDEA#2107):启用 Java 调试适配器,调试 Spring Boot 应用,断点命中。
5. 制造编译错误后运行,看到“Maven 编译失败”的提示,没有启动残缺的应用。
6. 整个过程中插件安装目录不被写入。
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ func installOfficialPluginArchive(t *testing.T, h *harness, archive, id string)
if err != nil {
t.Fatal(err)
}
// The app gives its service these resolvers when it opens it (app.go); a provider or backend
// that runs on a tool, such as a jar on java, cannot start without them.
service.Backend.SetToolResolver(h.app.resolveBackendTool)
service.Backend.SetToolEntryResolver(h.app.resolveBackendToolEntry)
service.LanguageTool = h.app.resolveLanguageTool
h.app.plugins = service
return installPluginArchiveInto(t, service, archive, id)
}

// installPluginArchiveInto installs and enables archive in service's plugin root, next to the
// plugins already there, and returns the installed package directory.
func installPluginArchiveInto(t *testing.T, service *pluginservice.Service, archive, id string) string {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
plan, err := service.Installer.Prepare(ctx, plugininstall.Request{ArchivePath: archive, Root: service.Root, Source: plugintrust.Disk})
Expand Down Expand Up @@ -154,11 +166,12 @@ func awaitBuildModel(t *testing.T, h *harness, p *project, buildSystemID string,
func runBuildTaskToEnd(t *testing.T, h *harness, p *project, projectID, taskID string, limit time.Duration) string {
t.Helper()
p.build.projectID, p.build.targetID, p.build.taskID = projectID, "", taskID
if _, err := h.app.runBuildTask(p, projectID, "", taskID, nil); err != nil {
op, err := h.app.runBuildTask(p, projectID, "", taskID, nil)
if err != nil {
t.Fatalf("start %s: %v", taskID, err)
}
awaitStateWithin(t, h, limit, "the "+taskID+" task", func() bool { return p.build.operation == nil })
output := strings.Join(p.build.output, "")
output := op.session.output.all()
if p.build.status != h.app.text.Build.Succeeded {
t.Fatalf("%s did not succeed: status=%q output=%q", taskID, p.build.status, output)
}
Expand Down
Loading
Loading