Skip to content

About

Automatically collects GraalVM reachability metadata for your project's dependencies by downloading the official metadata repository and copying matching entries into the build directory.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

GraalVM Reachability Metadata Gradle Plugin

A Gradle plugin that automatically collects GraalVM reachability metadata for your project's dependencies.

When building GraalVM native images, libraries that use reflection, JNI, dynamic proxies, or resource loading need metadata so native-image knows what to include. The GraalVM reachability metadata repository provides this metadata for many popular libraries. This plugin downloads the repository, walks your dependency graph, and copies the relevant metadata into your build directory — ready to be passed to native-image.

Motivation

The official GraalVM Native Build Tools Gradle plugin already includes a metadata repository feature. However, it has known issues with the Gradle configuration cache and does not work reliably in multi-module projects. These limitations can cause broken builds or force you to disable the configuration cache entirely — negating one of Gradle's most impactful performance features.

This plugin was created to work around those problems by re-implementing the metadata repository functionality with full configuration cache compatibility and correct behavior in multi-module setups.

Features

  • Automatic metadata collection — Resolves your runtimeClasspath and copies matching reachability metadata for every dependency.
  • Cached repository unpacking — The repository zip is downloaded once and unpacked under $GRADLE_USER_HOME, keyed by version. Subsequent builds reuse the cache.
  • Cacheable task — The collectReachabilityMetadata task is @CacheableTask, so Gradle can skip it or restore outputs from the build cache when inputs haven't changed.
  • Configurable — Exclude specific modules, override metadata versions per module, or change which classpath configuration is analyzed.

Usage

Apply the plugin in your build.gradle.kts:

plugins {
    id("io.github.bjoernmayer.graalvm-reachability-metadata")
}

That's it. The plugin registers a collectReachabilityMetadata task that you can run:

./gradlew collectReachabilityMetadata

The collected metadata will be written to build/generated/native-reachability-metadata/ by default.

Configuration

All settings are optional. Defaults are shown below:

reachabilityMetadata {
    // Version of the GraalVM reachability metadata repository to download
    repositoryVersion = "1.0.0"

    // Which configuration's dependencies to analyze
    classpathConfigurationName = "runtimeClasspath"

    // Where to copy the collected metadata
    outputDir = layout.buildDirectory.dir("generated/native-reachability-metadata")

    // Modules to exclude from metadata collection ("group:artifact")
    excludes = emptySet()
    // Example:
    // excludes.add("com.example:some-lib")

    // Override the metadata version used for specific modules ("group:artifact" -> "version")
    moduleToConfigVersion = emptyMap()
    // Example:
    // moduleToConfigVersion.put("com.example:some-lib", "1.2.3")

    // Fall back to the latest available metadata when the exact version is untested
    useLatestConfigWhenVersionIsUntested = true
}

Passing metadata to native-image

Point the GraalVM native image tool at the output directory:

graalvmNative {
    binaries {
        named("main") {
            configurationFileDirectories.from(tasks.named("collectReachabilityMetadata"))
        }
    }
}

Bundling metadata into the JAR

Alternatively, you can embed the metadata directly into your JAR so it is available at build time and on the classpath without extra configuration:

tasks.named("jar") {
    from(tasks.named("collectReachabilityMetadata"))
}

This automatically wires up task dependencies — Gradle will run collectReachabilityMetadata before jar and include the metadata files in the JAR output.

Example

The example/ directory contains a standalone Gradle project that applies the plugin and declares dependencies with known metadata entries. It uses includeBuild to load the plugin from source — no publishing step required.

cd example
../gradlew collectReachabilityMetadata

See example/README.md for details.

Developing

Checkout this repository next to some project where you want to use it. Then in the settings.gradle.kts of said project, add this:

// settings.gradle.kts

pluginManagement {
    includeBuild("../graalvm-reachability-metadata")
}

Then, you can just apply the plugin like usual:

// build.gradle.kts

plugins {
    id("io.github.bjoernmayer.graalvm-reachability-metadata")
}

Changes to the plugin source will be picked up automatically — no publishing step required.

Building

./gradlew :graalvm-reachability-metadata:build

Running checks

./gradlew :graalvm-reachability-metadata:check

This runs compilation, tests, and ktlint.

About

Automatically collects GraalVM reachability metadata for your project's dependencies by downloading the official metadata repository and copying matching entries into the build directory.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages