Skip to content

fix: 🐛 resolve transitive dependency types inside Kotlin-mirrored JARs - #183

Merged
maxandersen merged 2 commits into
jbangdev:mainfrom
philippart-s:fix-180
Oct 11, 2026
Merged

maxandersen merged 2 commits into
jbangdev:mainfrom
philippart-s:fix-180

Conversation

@philippart-s

Copy link
Copy Markdown
Contributor

Fixes #180

Problem

When a declared dependency is a Kotlin library (e.g. spring-ai-client-chat,
openai-java-core), types that its signatures reference from a sibling Java JAR
are reported as errors, although the script compiles with javac and runs with JBang:

  • Required type: ChatMemory / Provided: ChatMemory
  • Unknown class: 'com.fasterxml.jackson.databind.json.JsonMapper'

Cause

JBangKotlinLibraryMirror mirrors only the Kotlin JARs of the active root into a
module library so that K2 can build light classes. A class inside a mirrored JAR then
gets the module's resolve scope (LibraryRuntimeClasspathScope), which does not
include the root's plain Java JARs. Types from those JARs stay unresolved in the
mirrored class's signatures.

Classes in non-mirrored JARs are not affected: their resolve scope covers all
libraries.

Fix

JBangResolveScopeEnlarger now handles files inside a JBang JAR: their resolve scope
is enlarged with the full classpath of the root script that owns the JAR (the active
root if it owns it, otherwise the single owning root). Classpaths of different roots
are never merged, to avoid mixing dependency versions.

Tests

JBangLibraryProviderTest compiles two JARs (client referencing api.Memory as a
parameter and a return type) and highlights a script using them:

Full suite: 203 tests, 0 failures. Also checked manually with runIde on the
reproducers from #180 (Spring AI and OpenAI SDK).

CHANGELOG.md ([Unreleased]) and architecture.adoc are updated.

Classes in a JBang JAR mirrored as a module library (Kotlin support) were
resolved against the module classpath only, so types declared in sibling
Java JARs showed up as "Unknown class" or "Required type: X / Provided: X".
The resolve scope enlarger now gives classes inside a JBang JAR the owning
script's full classpath.

Fixes jbangdev#180
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • ai-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6556ef80-7ed6-41f6-9b50-cab97b59e7b2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@philippart-s
philippart-s marked this pull request as ready for review September 30, 2026 10:27
@philippart-s

Copy link
Copy Markdown
Contributor Author

👋 @maxandersen don't hesitate to ask me if you need more input 🤗

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Multi-root classpath isolation, a central invariant of the fix, lacks regression coverage.

1 open finding
What changed in this PR

Fixes transitive type resolution for classes inside Kotlin-mirrored JBang dependencies.

Changes:

  • Enlarges JAR resolve scopes using the owning script’s classpath.
  • Adds cross-JAR highlighting regression tests.
  • Updates architecture documentation and changelog.
File Description
CHANGELOG.md Documents the fix.
docs/​modules/​ROOT/​pages/​architecture.adoc Explains JAR resolve-scope behavior.
JBangResolveScopeEnlarger.kt Applies owning-root classpaths to JAR entries.
JBangProjectService.kt Determines the appropriate owning root.
JBangLibraryProviderTest.kt Tests cross-JAR type compatibility.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/main/kotlin/dev/jbang/idea/project/JBangProjectService.kt
Covers the Copilot review finding on jbangdev#183: when a dependency JAR is
shared by two root scripts with different classpaths, classes inside
that JAR must resolve against the active root's classpath only and must
not leak the other root's sibling JARs. Exercises the active-root
selection branch in getLibraryRootsForLibraryRoot.
@maxandersen

Copy link
Copy Markdown
Contributor

@philippart-s thanks for the fix - i added an additional test - let me know if you see issues with it. if not and the tests still passes i'll merge it.

@philippart-s

Copy link
Copy Markdown
Contributor Author

hi @maxandersen all tests pass 👌

@maxandersen
maxandersen merged commit 57b9ae4 into jbangdev:main Oct 11, 2026
9 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.

False "Required type: X / Provided: X" when the argument type comes from another jar

3 participants