Skip to content

Fix forge dockerBuildNative class-initialization conflicts - #15646

Merged
jamesfredley merged 1 commit into
apache:8.0.xfrom
jamesfredley:ci/forge-native-image-class-init
May 8, 2026
Merged

jamesfredley merged 1 commit into
apache:8.0.xfrom
jamesfredley:ci/forge-native-image-class-init

Conversation

@jamesfredley

Copy link
Copy Markdown
Contributor

Summary

Both grails-forge Cloud Run deploy workflows (Forge - Next GCP Deploy run 25514779324 and Forge - Prev Snapshot GCP Deploy run 25515077555) are currently failing at the dockerBuildNative step with GraalVM "was unintentionally initialized at build time" errors. This PR fixes the two distinct class-initialization conflicts that surface during native-image analysis.

Root cause

grails-forge-web-netty:dockerBuildNative

The Micronaut Gradle Application Plugin 4.6.2 transitively bundles the GraalVM Reachability Metadata Repository entry for ch.qos.logback/logback-classic at metadata-version 1.4.9 (visible in the build log as config-dirs/ch.qos.logback/logback-classic/1.4.9). That entry marks the entire ch.qos.logback package as --initialize-at-build-time, but the directive is incomplete for logback 1.5.x, which is what we ship (logbackClassicVersion=1.5.17, slf4jVersion=2.0.17). During native-image analysis, additional 1.5.x classes (StatusBase, Token, JoranConstants, StatusPrinter, LogbackClassicDefaultNestedComponentRules, ImplicitModelHandler$1, NodeToStringTransformer$1, org.slf4j.LoggerFactory, CoreConstants, Parser, Level, InfoStatus, PropertySetter$1, ChainedModelFilter$1, Parser$1, pattern.parser.Parser ...) get reached and reported as "unintentionally initialized at build time".

The official GRM repo already publishes a 1.5.7 metadata entry that covers logback 1.5.7 through 1.5.29 - the Micronaut Gradle plugin we use just doesn't pull it yet.

grails-forge-analytics-postgres:dockerBuildNative

The Args = --initialize-at-build-time=org.postgresql.Driver,org.postgresql.util.SharedTimer line in native-image.properties forced org.postgresql.Driver to initialize at build time, which transitively triggered java.sql.DriverManager.<clinit> to run at build time. Micronaut SQL registers java.sql.DriverManager for run-time initialization, producing the conflict reported as java.sql.DriverManager was unintentionally initialized at build time.

This manual override is also no longer needed: PostgreSQL 42.7.5 (the version we ship via postgresqlVersion=42.7.5) is officially covered by the GraalVM Reachability Metadata Repository (metadata-version 42.7.3, tested through 42.7.11), and micronaut-jdbc already ships --add-modules=java.sql.rowset for the rest of the JDBC support classes.

Changes

grails-forge-web-netty/.../native-image.properties

Add --initialize-at-run-time=ch.qos.logback,org.slf4j to override the bundled 1.4.9 build-time-init directive without touching reflection or resource configuration.

Args = -H:Name=grails-forge \
       -H:Class=org.grails.forge.netty.Application \
       --initialize-at-run-time=ch.qos.logback,org.slf4j

grails-forge-analytics-postgres/.../native-image.properties

Drop the manual --initialize-at-build-time=org.postgresql.Driver,org.postgresql.util.SharedTimer and replace with the same logback runtime-init override (this module also has runtimeOnly "ch.qos.logback:logback-classic:$logbackClassicVersion", so it will hit the same logback issue once the DriverManager error clears).

Args = --initialize-at-run-time=ch.qos.logback,org.slf4j

Both files are now header-commented to explain why these flags exist, matching the style used in the dockerfileNative block in grails-forge-web-netty/build.gradle and grails-forge-analytics-postgres/build.gradle for the GraalVM image pin.

Verification

  • ./gradlew :grails-forge-web-netty:processResources :grails-forge-analytics-postgres:processResources (offline) → exit 0; both native-image.properties files load via java.util.Properties.load(...) and produce the expected Args value.
  • The native-image analysis itself runs in the GraalVM Community 21.0.2 container during dockerBuildNative and is best verified by re-triggering the two workflow_dispatch workflows after this lands. RAT, code-style and the standard gradle.yml build are unaffected because the changes are confined to META-INF/native-image/**/native-image.properties, which is excluded from RAT (see gradle/rat-root-config.gradle).

References

The Micronaut Gradle Application Plugin 4.6.2 transitively pulls the
GraalVM Reachability Metadata Repository entry for ch.qos.logback at
metadata-version 1.4.9, which marks the package as
--initialize-at-build-time but does not cover the additional classes
introduced in logback 1.5.x. The analytics module also forced
org.postgresql.Driver to initialize at build time, which in turn
pulled java.sql.DriverManager into build-time init. As a result
dockerBuildNative failed with "* was unintentionally initialized at
build time" errors for logback, slf4j, and DriverManager when
deploying grails-forge to Cloud Run.

Override the bundled logback metadata locally so logback 1.5.x and
slf4j 2.x initialize at runtime, and rely on the official PostgreSQL
GRM metadata (which covers 42.7.3 through 42.7.11) plus Micronaut
SQL's runtime DriverManager registration instead of forcing
build-time initialization for the postgres driver.

Assisted-by: claude-code:claude-4.7-opus
Copilot AI review requested due to automatic review settings May 8, 2026 19:04

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 addresses GraalVM native-image (dockerBuildNative) class-initialization conflicts impacting Grails Forge deploy workflows by adjusting native-image configuration to avoid build-time initialization for problematic libraries (Logback/SLF4J) and removing an incompatible Postgres build-time init override.

Changes:

  • Add a Logback/SLF4J run-time initialization override (--initialize-at-run-time=ch.qos.logback,org.slf4j) to avoid build-time initialization conflicts caused by mismatched reachability metadata.
  • Remove the Postgres driver build-time initialization override that triggers a java.sql.DriverManager initialization conflict during native-image analysis.
  • Add explanatory header comments to both native-image.properties files documenting the rationale for these flags.

Reviewed changes

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

File Description
grails-forge/grails-forge-web-netty/src/main/resources/META-INF/native-image/org.grails.forge/grails-forge-web-netty/native-image.properties Adds run-time init override for Logback/SLF4J and documents why it’s needed for native builds.
grails-forge/grails-forge-analytics-postgres/src/main/resources/META-INF/native-image/io.micronaut.starter/micronaut-starter-analytics-postgres/native-image.properties Removes Postgres build-time init override and adds the same Logback/SLF4J run-time init override with rationale.

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

@jamesfredley
jamesfredley merged commit b47917c into apache:8.0.x May 8, 2026
34 of 35 checks passed
@jamesfredley
jamesfredley deleted the ci/forge-native-image-class-init branch May 8, 2026 19:09
@testlens-app

testlens-app Bot commented May 8, 2026

Copy link
Copy Markdown

🚨 TestLens detected 2 failed tests 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

Check Project/Task Test Runs
CI - Groovy Joint Validation Build / build_grails :grails-data-hibernate5-dbmigration:test GroovyChangeLogSpec > outputs a warning message by calling the warn method ❌
CI - Groovy Joint Validation Build / build_grails :grails-data-hibernate5-dbmigration:test GroovyChangeLogSpec > updates a database with Groovy Change ❌

🏷️ Commit: d48be12
▶️ Tests: 6426 executed
🟡 Checks: 13/35 completed

Test Failures

GroovyChangeLogSpec > outputs a warning message by calling the warn method (:grails-data-hibernate5-dbmigration:test in CI - Groovy Joint Validation Build / build_grails)
Condition not satisfied:

output.toString().contains('warn message')
|      |          |
|      |          false
|      19:15:51.568 [Test worker] INFO org.hibernate.dialect.Dialect -- HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
|      Running Changeset: changelog.groovy::2::John Smith
|       
|      UPDATE SUMMARY
|      Run:                          1
|      Previously run:               0
|      Filtered out:                 0
|      -------------------------------
|      Total change sets:            1
|       
|      Liquibase: Update has been successful. Rows affected: 1
19:15:51.568 [Test worker] INFO org.hibernate.dialect.Dialect -- HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Running Changeset: changelog.groovy::2::John Smith
 
UPDATE SUMMARY
Run:                          1
Previously run:               0
Filtered out:                 0
-------------------------------
Total change sets:            1
 
Liquibase: Update has been successful. Rows affected: 1

	at org.grails.plugins.databasemigration.liquibase.GroovyChangeLogSpec.outputs a warning message by calling the warn method(GroovyChangeLogSpec.groovy:87)
GroovyChangeLogSpec > updates a database with Groovy Change (:grails-data-hibernate5-dbmigration:test in CI - Groovy Joint Validation Build / build_grails)
Condition not satisfied:

output.toString().contains('confirmation message')
|      |          |
|      |          false
|      19:15:50.725 [Test worker] INFO org.hibernate.dialect.Dialect -- HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
|      Running Changeset: changelog.groovy::1::John Smith
|       
|      UPDATE SUMMARY
|      Run:                          1
|      Previously run:               0
|      Filtered out:                 0
|      -------------------------------
|      Total change sets:            1
|       
|      Liquibase: Update has been successful. Rows affected: 1
19:15:50.725 [Test worker] INFO org.hibernate.dialect.Dialect -- HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Running Changeset: changelog.groovy::1::John Smith
 
UPDATE SUMMARY
Run:                          1
Previously run:               0
Filtered out:                 0
-------------------------------
Total change sets:            1
 
Liquibase: Update has been successful. Rows affected: 1

	at org.grails.plugins.databasemigration.liquibase.GroovyChangeLogSpec.updates a database with Groovy Change(GroovyChangeLogSpec.groovy:61)

Muted Tests

Note

Checks are currently running using the configuration below.

Select tests to mute in this pull request:

🔲 GroovyChangeLogSpec > outputs a warning message by calling the warn method
🔲 GroovyChangeLogSpec > updates a database with Groovy Change

Reuse successful test results:

🔲 ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

🔲 Rerun jobs


Learn more about TestLens at testlens.app.

jamesfredley added a commit to jamesfredley/grails-core that referenced this pull request May 8, 2026
PR apache#15646 added --initialize-at-run-time=ch.qos.logback,org.slf4j to
override the GraalVM Reachability Metadata Repository 1.4.9 entry's
--initialize-at-build-time=ch.qos.logback directive, but
dockerBuildNative still failed: with --trace-class-initialization
enabled, native-image reports that org.eclipse.jgit.transport.Transport
caused build-time initialization of ch.qos.logback.core.CoreConstants
(and the rest of the logback class graph). Transport declares a
static final Logger LOG field, so forcing it to --initialize-at-
build-time in grails-forge-api/native-image.properties transitively
ran LoggerFactory.<clinit> and the whole logback init cascade at
build time, conflicting with our --initialize-at-run-time directive
on logback 1.5.x classes.

Two changes that together let dockerBuildNative succeed end-to-end
locally for both grails-forge-web-netty and grails-forge-analytics-
postgres on the Java 21 GraalVM Community 21.0.2-ol9 image, and let
the resulting native binaries actually start (web-netty serves HTTP
200 in 45ms; analytics-postgres reaches the postgres connection step):

1. Drop the manual --initialize-at-build-time list of jgit classes in
   grails-forge-api/src/main/resources/META-INF/native-image/org.grails.
   forge.api/grails-forge-api/native-image.properties. The list
   predates the GRM repo entry for org.eclipse.jgit, which now ships
   reflection and resource metadata covering jgit 6.5.0+; the manual
   list is the cascade source for the logback initialization at build
   time and is no longer necessary. Keep the existing one-class
   --initialize-at-run-time=org.eclipse.jgit.lib.internal.WorkQueue
   override (this one is opposite direction and unrelated).

2. Pin grails-forge-web-netty and grails-forge-analytics-postgres to
   GRM repo version 0.3.35 (released 2026-03-06) via
   graalvmNative.metadataRepository.version. The version bundled with
   the Micronaut Gradle Application Plugin 4.6.2 selects the
   logback-classic 1.4.9 metadata for our 1.5.17 runtime, whose
   --initialize-at-build-time=ch.qos.logback directive forces the
   conflict regardless of the JGit cascade. GRM 0.3.35 ships a 1.5.7
   metadata directory (covering 1.5.7-1.5.29, including our 1.5.17)
   that contains only reflection / resource configs and no
   --initialize-at-build-time directive, so logback initializes at
   the default (run-time) and our --initialize-at-run-time override
   applies unopposed. GRM 1.x release zips use a new repository
   layout that the GraalVMReachabilityMetadataService bundled with
   the current plugin does not understand, so we stay on the last
   compatible 0.3.x release with the updated logback metadata.

Verified locally with `./gradlew :grails-forge-web-netty:dockerBuildNative`
and `./gradlew :grails-forge-analytics-postgres:dockerBuildNative` on
Docker 29.3.0 against the Java 21 GraalVM Community 21.0.2-ol9 image
used by the Forge deploy workflows; both native binaries start.

Assisted-by: claude-code:claude-4.7-opus
jamesfredley added a commit to jamesfredley/grails-core that referenced this pull request May 8, 2026
PR apache#15646 added --initialize-at-run-time=ch.qos.logback,org.slf4j to
override the GraalVM Reachability Metadata Repository 1.4.9 entry's
--initialize-at-build-time=ch.qos.logback directive, but
dockerBuildNative still failed: with --trace-class-initialization
enabled, native-image reports that org.eclipse.jgit.transport.Transport
caused build-time initialization of ch.qos.logback.core.CoreConstants
(and the rest of the logback class graph). Transport declares a
static final Logger LOG field, so forcing it to --initialize-at-
build-time in grails-forge-api/native-image.properties transitively
ran LoggerFactory.<clinit> and the whole logback init cascade at
build time, conflicting with our --initialize-at-run-time directive
on logback 1.5.x classes.

Two changes that together let dockerBuildNative succeed end-to-end
locally for both grails-forge-web-netty and grails-forge-analytics-
postgres on the Java 21 GraalVM Community 21.0.2-ol9 image, and let
the resulting native binaries actually start (web-netty serves HTTP
200 in 45ms; analytics-postgres reaches the postgres connection step):

1. Drop the manual --initialize-at-build-time list of jgit classes in
   grails-forge-api/src/main/resources/META-INF/native-image/org.grails.
   forge.api/grails-forge-api/native-image.properties. The list
   predates the GRM repo entry for org.eclipse.jgit, which now ships
   reflection and resource metadata covering jgit 6.5.0+; the manual
   list is the cascade source for the logback initialization at build
   time and is no longer necessary. Keep the existing one-class
   --initialize-at-run-time=org.eclipse.jgit.lib.internal.WorkQueue
   override (this one is opposite direction and unrelated).

2. Pin grails-forge-web-netty and grails-forge-analytics-postgres to
   GRM repo version 0.3.35 (released 2026-03-06) via
   graalvmNative.metadataRepository.version. The version bundled with
   the Micronaut Gradle Application Plugin 4.6.2 selects the
   logback-classic 1.4.9 metadata for our 1.5.17 runtime, whose
   --initialize-at-build-time=ch.qos.logback directive forces the
   conflict regardless of the JGit cascade. GRM 0.3.35 ships a 1.5.7
   metadata directory (covering 1.5.7-1.5.29, including our 1.5.17)
   that contains only reflection / resource configs and no
   --initialize-at-build-time directive, so logback initializes at
   the default (run-time) and our --initialize-at-run-time override
   applies unopposed. GRM 1.x release zips use a new repository
   layout that the GraalVMReachabilityMetadataService bundled with
   the current plugin does not understand, so we stay on the last
   compatible 0.3.x release with the updated logback metadata.

Verified locally with `./gradlew :grails-forge-web-netty:dockerBuildNative`
and `./gradlew :grails-forge-analytics-postgres:dockerBuildNative` on
Docker 29.3.0 against the Java 21 GraalVM Community 21.0.2-ol9 image
used by the Forge deploy workflows; both native binaries start.

Assisted-by: claude-code:claude-4.7-opus
jamesfredley added a commit that referenced this pull request May 8, 2026
PR #15646 added --initialize-at-run-time=ch.qos.logback,org.slf4j to
override the GraalVM Reachability Metadata Repository 1.4.9 entry's
--initialize-at-build-time=ch.qos.logback directive, but
dockerBuildNative still failed: with --trace-class-initialization
enabled, native-image reports that org.eclipse.jgit.transport.Transport
caused build-time initialization of ch.qos.logback.core.CoreConstants
(and the rest of the logback class graph). Transport declares a
static final Logger LOG field, so forcing it to --initialize-at-
build-time in grails-forge-api/native-image.properties transitively
ran LoggerFactory.<clinit> and the whole logback init cascade at
build time, conflicting with our --initialize-at-run-time directive
on logback 1.5.x classes.

Two changes that together let dockerBuildNative succeed end-to-end
locally for both grails-forge-web-netty and grails-forge-analytics-
postgres on the Java 21 GraalVM Community 21.0.2-ol9 image, and let
the resulting native binaries actually start (web-netty serves HTTP
200 in 45ms; analytics-postgres reaches the postgres connection step):

1. Drop the manual --initialize-at-build-time list of jgit classes in
   grails-forge-api/src/main/resources/META-INF/native-image/org.grails.
   forge.api/grails-forge-api/native-image.properties. The list
   predates the GRM repo entry for org.eclipse.jgit, which now ships
   reflection and resource metadata covering jgit 6.5.0+; the manual
   list is the cascade source for the logback initialization at build
   time and is no longer necessary. Keep the existing one-class
   --initialize-at-run-time=org.eclipse.jgit.lib.internal.WorkQueue
   override (this one is opposite direction and unrelated).

2. Pin grails-forge-web-netty and grails-forge-analytics-postgres to
   GRM repo version 0.3.35 (released 2026-03-06) via
   graalvmNative.metadataRepository.version. The version bundled with
   the Micronaut Gradle Application Plugin 4.6.2 selects the
   logback-classic 1.4.9 metadata for our 1.5.17 runtime, whose
   --initialize-at-build-time=ch.qos.logback directive forces the
   conflict regardless of the JGit cascade. GRM 0.3.35 ships a 1.5.7
   metadata directory (covering 1.5.7-1.5.29, including our 1.5.17)
   that contains only reflection / resource configs and no
   --initialize-at-build-time directive, so logback initializes at
   the default (run-time) and our --initialize-at-run-time override
   applies unopposed. GRM 1.x release zips use a new repository
   layout that the GraalVMReachabilityMetadataService bundled with
   the current plugin does not understand, so we stay on the last
   compatible 0.3.x release with the updated logback metadata.

Verified locally with `./gradlew :grails-forge-web-netty:dockerBuildNative`
and `./gradlew :grails-forge-analytics-postgres:dockerBuildNative` on
Docker 29.3.0 against the Java 21 GraalVM Community 21.0.2-ol9 image
used by the Forge deploy workflows; both native binaries start.

Assisted-by: claude-code:claude-4.7-opus
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.

2 participants