fix: resolve JVM imports in multi-module Maven/Gradle projects (0 edges bug)#22
Merged
giancarloerra merged 1 commit intogiancarloerra:mainfrom Apr 11, 2026
Conversation
Single-module resolution (src/main/java/…) already worked. Multi-module layouts like: module-a/sub/src/main/java/com/example/Foo.java were silently unresolved because the three fixed src-dir prefixes never matched. The dependency graph therefore always produced 0 edges for any Java/Kotlin/Scala project that follows the standard Maven/Gradle multi-module layout. Fix: introduce `buildJvmSuffixMap()` which scans `fileSet` once (O(n)) and registers every JVM source file by its class-path key (i.e. everything after src/main/<lang>/). `resolveImport` accepts the map as an optional last argument and falls back to it when the existing prefix-based approach yields no result. - `buildJvmSuffixMap` exported for reuse / testing. - Map is built once per `buildCodeGraph` call, only when the project contains at least one JVM file — zero cost for other language projects. - Lookup is O(1) per import, replacing a worst-case O(n) linear scan on every miss. - Works on both Windows (backslash) and POSIX (forward-slash) because the map key is built with `path.sep`. - 7 new unit tests covering: map construction, test-source exclusion, multi-module Java resolution, Kotlin resolution, unresolvable class, stdlib guard. Fixes: enterprise Java/Spring Boot codebases (30+ Maven modules) reporting 0 edges in codebase_graph_stats. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Owner
|
Thanks merged! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Any Java/Kotlin/Scala project using a multi-module Maven or Gradle layout produces
0dependency edges incodebase_graph_stats, makingcodebase_graph_query,codebase_graph_circular, andcodebase_graph_visualizeuseless for the majority of real-world JVM codebases.Tested on a 30-module Spring Boot monorepo (~29,000 Java files):
Root cause
resolveImportalready had correct import parsing and FQN→path conversion for Java. The resolution failed silently because the fallback directory list was limited to three fixed prefixes:A multi-module project places sources at:
None of the three prefixes match when resolved from the project root, so every cross-module import returned
null.Fix
Introduce
buildJvmSuffixMap(fileSet)— a one-time O(n) scan that registers every JVM file by its class-path key (everything aftersrc/main/<lang>/):resolveImportaccepts the map as an optional last argument and falls back to an O(1) map lookup when the existing prefix approach fails.buildCodeGraphbuilds the map once per graph build, only when the project contains JVM files — zero overhead for non-JVM projects.Changes
src/services/graph-resolution.tsbuildJvmSuffixMap; addjvmSuffixMap?param toresolveImport; use it in Java/Kotlin/Scala casesrc/services/code-graph.tsresolveImporttests/unit/graph-resolution.test.tsCompatibility
jvmSuffixMapis optional; single-module projects continue to resolve via the existing prefix approach without reaching the suffix map.path.sep.Testing
All 7 new unit tests pass. The 42 pre-existing test failures on Windows are unrelated path-separator issues in the test harness (
/vs\) that existed before this PR.Relates to issue #21 — Java dependency graph support
🤖 Co-authored with Claude Code