Skip to content

Fix forge dockerBuildNative by using a Java 21 GraalVM base image - #15579

Merged
jamesfredley merged 2 commits into
8.0.xfrom
fix/forge-graalvm-java21-native-image
Apr 16, 2026
Merged

jamesfredley merged 2 commits into
8.0.xfrom
fix/forge-graalvm-java21-native-image

Conversation

@jamesfredley

Copy link
Copy Markdown
Contributor

Summary

  • The Forge prev-snapshot GCP deploy workflow (example failed run) builds the application with Java 21 (actions/setup-java + javaVersion=21 in gradle.properties), but the dockerfileNative task pinned baseImage('ghcr.io/graalvm/jdk:ol8-java17-22.3.3'). That GraalVM image runs native-image on Java 17, so it rejects the Java 21 bytecode and aborts with UnsupportedClassVersionError (class file version 65.0).
  • Both grails-forge-web-netty:dockerBuildNative and grails-forge-analytics-postgres:dockerBuildNative failed for the same reason.
  • Switch the baseImage in both modules to ghcr.io/graalvm/native-image-community:21, the canonical GraalVM Community image for Java 21 that ships with the native-image tool, matching the project's Java baseline.

Failure excerpt

Fatal error: java.lang.UnsupportedClassVersionError: org/grails/forge/netty/Application
  has been compiled by a more recent version of the Java Runtime (class file version 65.0),
  this version of the Java Runtime only recognizes class file versions up to 61.0
Error: Image build request failed with exit status 1
> Task :grails-forge-web-netty:dockerBuildNative FAILED

Verification

  • dockerBuildNative cannot be exercised in this environment (no Docker runtime), but the new image is the standard GraalVM Community Java 21 image used by the upstream Micronaut Starter project for the same task.
  • No application code changes; only the GraalVM build container reference is updated.

Notes for reviewers

  • Targeting 8.0.x because that is the branch where the deploy workflow runs and where the failure was observed.
  • The fix/ branch prefix should auto-label this PR as a bug per .github/release-drafter.yml.

The Forge prev-snapshot GCP deploy workflow compiles the application with Java 21 but the dockerfileNative task pinned baseImage to ghcr.io/graalvm/jdk:ol8-java17-22.3.3, whose native-image tool only accepts class file version 61.0 (Java 17). The build failed with UnsupportedClassVersionError for both grails-forge-web-netty and grails-forge-analytics-postgres.

Switch the baseImage to ghcr.io/graalvm/native-image-community:21, the canonical GraalVM Community image for Java 21 that bundles the native-image tool, matching the project's javaVersion=21 baseline and the workflow's setup-java configuration.

Assisted-by: Claude Code <[email protected]>
Copilot AI review requested due to automatic review settings April 16, 2026 14:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Grails Forge native-image Docker build configuration to align the dockerBuildNative container image with the project’s Java 21 compilation baseline, avoiding native-image failures caused by running on a Java 17 GraalVM image.

Changes:

  • Update dockerfileNative base image in Forge Netty web module to a Java 21 GraalVM Native Image community image.
  • Update dockerfileNative base image in Forge analytics-postgres module to the same Java 21 GraalVM Native Image community image.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
grails-forge/grails-forge-web-netty/build.gradle Switches native-image Docker base image to a Java 21 GraalVM Native Image community image.
grails-forge/grails-forge-analytics-postgres/build.gradle Switches native-image Docker base image to a Java 21 GraalVM Native Image community image.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Address Copilot review feedback on PR #15579: replace the floating major tag ghcr.io/graalvm/native-image-community:21 with the fully pinned 21.0.2-ol9 tag, restoring the patch-level pinning that the previous ghcr.io/graalvm/jdk:ol8-java17-22.3.3 reference provided.

21.0.2 is the final GraalVM Community release for JDK 21 (verified against ghcr.io/graalvm/native-image-community); later GraalVM Community releases target JDK 22+.

Assisted-by: Claude Code <[email protected]>
@jamesfredley
jamesfredley merged commit f27a90b into 8.0.x Apr 16, 2026
28 checks passed
@jamesfredley
jamesfredley deleted the fix/forge-graalvm-java21-native-image branch April 16, 2026 15:21
@jamesfredley

Copy link
Copy Markdown
Contributor Author

jamesfredley added a commit that referenced this pull request Apr 16, 2026
PR #15579 updated the `dockerfileNative` baseImage to
`ghcr.io/graalvm/native-image-community:21.0.2-ol9`, but the
Forge prev-snapshot GCP deploy workflow still fails with
`UnsupportedClassVersionError: class file version 65.0` because
the generated Dockerfile's builder stage continues to emit:

    Step 1/13 : FROM ghcr.io/graalvm/native-image:ol7-java17-22.3.2 AS graalvm

On Micronaut Gradle Plugin 3.7.10 (our pinned
micronautApplicationPluginVersion), `baseImage(...)` on the
`dockerfileNative` task only affects the final runtime stage of
the multi-stage Dockerfile. The builder stage (`FROM ... AS graalvm`),
where the `native-image` tool actually runs against our Java 21
bytecode, is controlled by the separate `graalImage` property.

`graalImage`'s convention is derived from `jdkVersion` via
`toGraalVMBaseImageName(graalVersion, jdkVersion)` ->
`ghcr.io/graalvm/native-image:ol7-${jdkVersion}-${graalVersion}`,
and `jdkVersion` is clamped by `NativeImageDockerfile.toSupportedJavaVersion`
against `SUPPORTED_JAVA_VERSIONS = [17, 11]`. That silently rounds
Java 21 down to Java 17, so even with the toolchain set to 21
the builder image still resolves to a Java 17 container that
rejects class file version 65.0.

Explicitly set `graalImage` to the same Java 21 community image
we use for the runtime stage so both stages of the generated
Dockerfile run on Java 21. This unblocks the failing job
`grails-forge-web-netty:dockerBuildNative` (and the analytics
module) on 8.0.x:

  https://github.com/apache/grails-core/actions/runs/24518601227

A longer-term fix is to upgrade `micronautApplicationPluginVersion`
from 3.7.10 to 4.x, which adds first-class Java 21 and
`native-image-community` support, but that is a larger change;
this two-line override unblocks CI now.

Assisted-by: claude-code:claude-opus-4-7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants