Skip to content

Verify native-image behaviour with an end-to-end native build #16176

Open

Description

@codeconsole

Background

Grails 8 now has a native-image build path: #16094 added processAot wiring, cooperation with org.graalvm.buildtools.native, and the GenerateNativeMetadataTask / TraceNativeMetadataTask machinery, and #16102 moved i18n onto Spring Boot's MessageSource with an I18nRuntimeHintsProcessor that registers resource hints for the effective spring.messages.basename.

What neither PR established is a build that actually compiles a native binary and runs it. Today:

  • nothing in the repository invokes nativeCompile, nativeRun or nativeTest;
  • no CI workflow provisions GraalVM or mentions native-image;
  • grails-test-examples/aot verifies processAot output and a JVM startup check, both of which run on a normal JDK.

So every native-image claim in the framework currently rests on JVM-level AOT processing plus reasoning about the metadata, rather than on a binary that was built and exercised. That is a reasonable place to have landed the feature work, but it leaves a gap worth closing deliberately.

Proposal

Add a native-image verification target — most likely under end-to-end/, since it already consumes published artifacts — that builds a real GraalVM binary from a Grails application and asserts runtime behaviour that only a native image can falsify.

Suggested first assertions, ordered by how likely they are to catch something:

  1. Plugin message bundles resolve. A namespaced plugin bundle (for example spring-security-core_fr.properties) resolving in the binary. This is the case Spring Boot's own MessageSourceRuntimeHints does not cover — it registers two hardcoded messages* patterns and derives nothing from the configured base names — so if I18nRuntimeHintsProcessor is wrong, plugin messages resolve on the JVM and silently vanish in native.
  2. A base name the application configured itself resolves, e.g. spring.messages.basename: config/i18n/custom, covering the dot-to-slash path conversion.
  3. The i18n descriptor is readable, since base-name discovery reads META-INF/grails/i18n.properties through an exact-name ClassLoader.getResources lookup at runtime.
  4. Whatever equivalent assertions the AOT cache and native metadata work from Make Grails applications processable by Spring AOT (Leyden AOT Cache + GraalVM Native Image Support) #16094 would want.

Open question worth settling with the test

I18nRuntimeHintsProcessor uses the same hint API Spring Boot uses. Boot's MessageSourceRuntimeHints calls registerPattern (verified in spring-boot-autoconfigure 4.1.0: it references registerPattern, messages.properties and messages_*.properties, and never registerResourceBundle), and this processor does the same. The difference is coverage, not mechanism: Boot registers two hardcoded messages* patterns and derives nothing from the configured base names, whereas this one generates patterns from the effective spring.messages.basename, which is what brings namespaced plugin bundles along.

The open question is only whether the more precise hints.resources().registerResourceBundle(...) would also work. It exists and is the more obvious API for message bundles, yet Boot does not use it. The likely reason is that it serialises to a {"bundle": ...} entry, which GraalVM resolves against the image's included locale set, so non-default locales could drop out — but that is inferred from reading the serialisation code, not documented by Boot or confirmed against a binary. A native test would settle it. If registerResourceBundle turns out to be safe, the hints could become more precise.

Notes

  • This is framework-wide infrastructure, not specific to i18n: a native job would serve the AOT cache work, GORM, GSP and anything else that ships hints.
  • Cost is the main design question. A full nativeCompile is minutes of CPU and needs a GraalVM toolchain, so it probably belongs on a scheduled or opt-in workflow rather than every PR.

Raised from review discussion on #16102.

Activity

  1. codeconsole commented on Sep 11, 2026

    @codeconsole
    ContributorAuthor

    Native image is blocked upstream, on Groovy rather than on hints

    #16180 adds the module this issue asks for, and @matrei built and ran the binary — the half nobody had done. The result is that the open question above cannot be settled yet, for reasons that have nothing to do with I18nRuntimeHintsProcessor.

    Dynamic Groovy does not run in a native image on any released Groovy, whichever way it is compiled:

    Compiled What the image does
    without invokedynamic Groovy classes carry a CallSiteArray and define call-site classes as they run, which an image forbids: UnsupportedFeatureError: Tried to define class
    with invokedynamic the runtime linkage invokes IndyInterface's bootstrap method without its <clinit> having run, so a static final handle is still null: BootstrapMethodError: NullPointerException at IndyInterface.makeBootHandle

    Reproduced by @matrei with a ten-line Groovy hello-world — no Spring, no Grails, metadata from the tracing agent — against both 5.1.2 and 4.0.27, so it is not a Grails metadata gap. Registering every IndyInterface method for reflection changes nothing, --exact-reachability-metadata reports no missing registration, and --initialize-at-build-time fails on image-heap objects.

    Two upstream blockers, then:

    1. GROOVY-12234 — an AOT link mode for indy dispatch. On the Groovy 6 line and in no 5.x release. Grails 8.0.x pins groovy.version 5.1.2, whose IndyInterface carries neither aotDispatch nor the ensureInitialized guard that 6.0.0-RC-1 added. Related: GROOVY-12227, and in the unreleased 6.0.0-RC-2 GROOVY-12364/12365/12366 (reachability metadata and native-image.properties shipped in the groovy jar).
    2. oracle/graal#10200 — GraalVM's bundled Groovy substitution targets IndyInterface.invalidateSwitchPoints(), which Groovy 4+ removed, so nativeCompile fails during "Initializing" on the GraalVM 21 line. Fixed in the 25 line.

    There is a third, inside Grails: CompilePlugin defaults grailsIndy to false for published artifacts, because Groovy 5's indy default is a large runtime regression for dynamic Groovy (#15293). So a released Grails 8 could not produce an image even once Groovy and GraalVM are fixed. Its own comment already records Grails 9 / Groovy 6 as where that can flip — the same boundary as blocker 1, which is convenient, but it should be a deliberate decision rather than a coincidence.

    What this means for the issue

    • The module in Start Grails as a native image without recorded metadata, checked by an end-to-end i18n module #16180 lands with the JVM half in check and the native half behind -PnativeTests, documented as not passing. It is written so it starts passing when the above land rather than having to be authored then.
    • The registerPattern vs registerResourceBundle question stays open. It needs a binary to settle, and no binary is buildable from a released toolchain today.
    • Worth deciding separately, and bigger than this issue: configureNativeImage and the upgrade guide currently imply native image is a Grails 8 capability. On Groovy 5 it is not one, for any application. Either that wiring is documented as forward-looking, or the claim moves to the release where it is true.

    Cheapest way to learn when the gap closes, per @matrei: the snapshot canary workflow already rebuilds Grails against a Groovy branch by rewriting groovy.version. Running native-i18n in that job on GraalVM 25, once 6.0.0-RC-2 ships, would tell us without anyone having to re-derive this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions