Skip to content

fix(navigation): 修复 Gradle 项目无法跳转到已缓存依赖(#4) - #13

Merged
1lck merged 5 commits into
mainfrom
devin/1795696112-4-gradle-dependency-navigation
Nov 27, 2026
Merged

1lck merged 5 commits into
mainfrom
devin/1795696112-4-gradle-dependency-navigation

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4

Summary

Java Support Lite 现在能从 Gradle 项目跳到已缓存依赖的源码或签名存根。此前,即使 Spring Boot 工程已成功编译,插件仍然会报告 0 个依赖 JAR。

  • 从 Groovy/Kotlin 构建脚本读取常用 Java 依赖配置中的字面量坐标和默认版本目录的库别名。扫描时跟踪构建脚本与版本目录的变化。
  • 在 Gradle 用户缓存中查找二进制 JAR、源码 JAR 和 POM,复用现有 POM 解析器跟进传递依赖。省略版本时使用本地最高版本。解析范围限于静态声明,动态脚本、bundle 和变体选择见 README。
  • 用 TOML 库读取版本目录,并在插件包内附带其许可证。SDK 许可证移至 licenses/,避免根目录 vendor/ 意外启用 Go 的 vendor 模式。

复现与复测

在 Linux x64 上通过真实 LSP 对 Spring 官方 REST 示例发起定义请求。使用 Gradle 构建,保留已下载的依赖,前后各启动三个独立的语言服务器,种子和 33 个位置一致。复现评论

指标 修复前 修复后
识别的依赖 JAR 0 65
命中 18/33 25/33
首次跳转 4 ms 53–56 ms
查询结束 RSS 8 MiB 12–13 MiB

7 个新增目标均位于 Spring 依赖中,包括 SpringApplication.run 与 @RestController。两组均未加载 JDK 源码。

版本目录变更后跳转的回归测试在修复前失败,修复后通过。另有用例覆盖分散在不同哈希目录的源码与二进制、传递 POM、指定版本缺失、忽略注释及未声明的依赖。已通过 go vet ./...、全量 Go 竞态测试、六个平台归档构建、Linux 归档校验和 Linux x64 安装包 LSP 冒烟测试。

Link to Devin session: https://app.devin.ai/sessions/8968c13d203f4024bb0c72024a73dde1
Open in Devin Desktop: https://app.devin.ai/desktop/session/8968c13d203f4024bb0c72024a73dde1?variant=devin
Requested by: @1lck


Devin Review

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

devin-ai-integration[bot]

This comment was marked as resolved.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
devin-ai-integration[bot]

This comment was marked as resolved.

… indexable

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
devin-ai-integration[bot]

This comment was marked as resolved.

…ons together

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 new potential issues.

4 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment thread internal/deps/gradle.go
Comment on lines +37 to +44
dir := filepath.Dir(p)
if _, ok := projects[dir]; !ok {
directories = append(directories, dir)
projects[dir] = gradleDeclarations(readGradleFile(p), catalog)
}
}
var primary, extra []*model
for _, dir := range directories {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Scriptless subprojects lose dependency navigation

GradleJars skips included subprojects without build scripts, even when the root configures them through subprojects. Their cached dependencies never enter the navigation index.

Learn more

Gradle can configure an included project entirely from the root build script, so that project does not need its own build file. depInputs passes only existing build scripts to the dependency resolver. gradleDeclarations puts dependencies declared in subprojects into the child-only group. No model consumes that group when all included projects lack build scripts, so the cached JARs never enter the index.

Example: The root settings declares include(":service"). The root build script applies the Java plugin and declares Guava inside subprojects. service has Java sources but no build script. Gradle compiles the sources against Guava, but Go to Definition cannot open Guava classes from those sources.

Recommended fix: Discover conventional subproject directories from literal include declarations in the settings files and create an empty local dependency model for each included project without a script, then merge the inherited declarations. Add a regression test with only a root build script and a scriptless included Java subproject.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread internal/deps/gradle.go
Comment on lines +46 to +55
for child := dir; filepath.Dir(child) != child; child = filepath.Dir(child) {
// A nested build with its own settings does not inherit the
// outer build's subprojects declarations.
if _, err := os.Stat(filepath.Join(child, "settings.gradle")); err == nil {
break
}
if _, err := os.Stat(filepath.Join(child, "settings.gradle.kts")); err == nil {
break
}
for group, shared := range projects[filepath.Dir(child)].children {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Outer dependencies override buildSrc versions

GradleJars merges outer subprojects dependencies into buildSrc when it has no settings file. A higher outer version displaces the JAR that buildSrc actually compiles against.

Learn more

Gradle treats the root’s buildSrc directory as a separate build even without a settings file in that directory. depInputs collects its build script alongside ordinary subproject scripts. The directory walk merges the outer project’s declarations into that independent model. resolveGradle chooses a single winning version per dependency, so the actual buildSrc JAR is never indexed when only that model requests it and the inherited version wins.

Example: buildSrc/build.gradle declares org.example:helper:1, and the root’s subprojects block declares org.example:helper:2 for the application modules. buildSrc compiles against version 1, but the index drops it. A class found only in version 1 no longer has a definition target.

Recommended fix: Treat a Gradle build’s conventional buildSrc directory as a build boundary even without a local settings file. Preserve inheritance inside buildSrc while preventing inheritance across that boundary. Cover this with conflicting dependency versions in the outer build and buildSrc.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@1lck
1lck merged commit 178c493 into main Nov 27, 2026
6 checks passed
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.

Gradle 项目的依赖库跳转

1 participant