A Scala tool for filtering GraalVM native image reachability metadata files to remove entries that don't exist in your main application classpath. This helps reduce the size of your native image metadata by removing test-only classes and dependencies.
This tool processes GraalVM reachability metadata JSON files (typically located in resources/META-INF/native-image/) and filters out:
- Reflection entries for classes that don't exist in the main classpath
- JNI entries for classes that don't exist in the main classpath
- Serialization entries for classes that don't exist in the main classpath
It preserves:
- Resource entries (no type information to filter)
- Bundle entries (no type information to filter)
- Foreign function interface entries (no type information to filter)
scala run --dep ma.chinespirit::filter-native-image-metadata:0.1.2 -M filterNativeImageMetadata -- <metadata-file> <main-classpath> <test-classpath><metadata-file>: Path to the reachability metadata file, usually located inresources/META-INF/native-image/<main-classpath>: Classpath for the main application (e.g.,scala compile -p .)<test-classpath>: Classpath for the test application (e.g.,scala compile --test -p .)
# Filter the metadata
scala run --dep ma.chinespirit::filter-native-image-metadata:0.1.2 filterNativeImageMetadata -- \
resources/META-INF/native-image/reachability-metadata.json \
$(scala compile -p .) \
$(scala compile --test -p .)- Loads classloaders for both main and test classpaths
- Parses the metadata JSON using the official GraalVM reachability metadata schema
- Filters entries by checking if the referenced classes exist in the main classloader
- Handles complex types like proxy types and lambda types by checking all their dependencies
- Writes the filtered metadata back to the original file
The tool supports the complete GraalVM reachability metadata schema v1.1.0, including:
- Reflection entries with methods, fields, and access modifiers
- JNI entries for native method access
- Serialization entries for Java serialization
- Resource entries (glob patterns and bundles)
- Foreign function interface entries
- Complex type descriptors (proxy types, lambda types)
- Scala 3.3+
- GraalVM reachability metadata files in JSON format (generated by native-image agent)
MIT License - see LICENSE.md for details.