Repository navigation
fix(client): add GraalVM Native Image reachability metadata - #407
Open
katinguengan wants to merge 1 commit into
Open
katinguengan wants to merge 1 commit into
katinguengan wants to merge 1 commit into
Conversation
Generate reflect-config.json for anthropic-java-core from the compiled classes at build time, so Jackson and Kotlin reflection work in native images. Fixes anthropics#406
katinguengan
force-pushed
the
feat/graalvm-agent-metadata-generation
branch
from
October 8, 2026 10:30
a5d112c to
bec7a8f
Compare
This branch has not been deployed
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.
Fixes #406
Summary
anthropic-java-corenow ships GraalVM Native Image reachability metadata, so Jackson and Kotlin reflection work in native images without users adding their own hints.The metadata is generated from the compiled classes every time the jar is built. It doesn't depend on CI, on the publishing workflows, or on what the test suite exercises.
Problem
In a native image, every SDK call fails before a request is sent:
Jackson and Kotlin reflection reach SDK classes reflectively, and native images only allow reflection on classes that are registered ahead of time.
Changes
buildSrc/src/main/kotlin/NativeImageMetadata.kt(new)A cacheable Gradle task that loads the module's compiled classes and writes
META-INF/native-image/com.anthropic/anthropic-java-core/reflect-config.json. It registers whatMETA-INF/proguard/anthropic-java-core.proalready keeps:@Metadataannotation names;Each entry only applies when its class is reachable in the image (
typeReachablecondition), so unused types add nothing to the image.anthropic-java-core/build.gradle.ktsRegisters the task and adds its output to the main resources, so the metada
Validation
All runs used
main(2.70.0) plus this change, Oracle GraalVM 25.0.4 on maBoot 4.1.1 / Spring AI 2.0.1 app from #406 without any user-supplied hints.mainUnresolved class: …MessageCreateParams$BodyJsonValue$Deserializer has no default (no arg) constructor:anthropic-java-core:test:anthropic-java-core:testJacksonPublishedA standalone SDK app (no Spring) built as a native image showed the same before/after result for chat, streaming and tool calling.
Trade-off: image size
The metadata covers the whole API, so every model class Jackson may create . That makes native images larger:
Most SDK classes are reachable anyway, because the client references every service, so the
typeReachablecondition only partly offsets this. A smaller metadata set would have to list only the classes a particular test run exercised, which brings back the missing-class failures for everything else.