fix: resolve JVM imports in Gradle/Maven module source roots - #739
ariancovac wants to merge 1 commit into
Conversation
Multi-module Gradle/Maven projects keep each module's sources under <module>/src/main/java|kotlin (e.g. android/src/main/java). The Java and Kotlin import resolvers only tried scan-root-relative paths, so in multi-module projects every cross-file import failed to resolve, the import graph came back empty, and graph-based detectors (orphaned, coupling, cycles, single_use) flagged essentially the whole codebase. Discover src/main/java and src/main/kotlin roots under the scan path (pruning build output), memoized per scan root, and try them before the historical fallbacks.
|
Reviewed against current The existing test failure is introduced by this PR, not pre-existing. Restoring Follow-up (non-blocking): Also note |
Problem
Multi-module Gradle/Maven projects keep each module's sources under a module directory (
android/src/main/java,feature/x/src/main/kotlin). The Java and Kotlin import resolvers only tried scan-root-relative paths (src/main/java,src,app/src/main/java,.), so in any multi-module project every cross-file import failed to resolve:importer_count == 0for essentially the whole codebase,MainActivity,MediaKitApplication, andsettings.gradle.kts.Verified against a real 3-module Android project (modules
android/,download-private/,detekt-rules/): before the fix, 118/120 source files were flagged orphaned; after the fix, 0.Fix
discover_jvm_source_roots(scan_path)toresolver_cache.py: anos.walk(pruningbuild/,node_modules/, dot-dirs, depth-capped) that finds<module>/src/main/java|kotlinroots, memoized per scan root and cleared byreset_import_cache().resolve_java_import/resolve_kotlin_importnow try the discovered module roots first, then the historical fallbacks (behavior for single-module/flat layouts is unchanged).test_jvm_resolvers_find_imports_in_gradle_modulescovers Kotlin + Java module resolution, ensures build-output copies never win over real sources, and exercises the cache reset.Full suite: 601 passed in
tests/lang(the 2 failures intest_treesitter_imports_direct.py—test_backend_import_resolvers_cover_language_specific_paths,test_script_import_resolvers_cover_cached_paths_and_extensions— also fail on cleanmainon Windows; pre-existing, unrelated).