Repository navigation
Fix forge dockerBuildNative class-initialization conflicts - #15646
Conversation
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
There was a problem hiding this comment.
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.DriverManagerinitialization conflict during native-image analysis. - Add explanatory header comments to both
native-image.propertiesfiles 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.
🚨 TestLens detected 2 failed tests 🚨Here is what you can do:
Test Summary
🏷️ Commit: d48be12 Test FailuresGroovyChangeLogSpec > outputs a warning message by calling the warn method (:grails-data-hibernate5-dbmigration:test in CI - Groovy Joint Validation Build / build_grails)GroovyChangeLogSpec > updates a database with Groovy Change (:grails-data-hibernate5-dbmigration:test in CI - Groovy Joint Validation Build / build_grails)Muted TestsNote 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 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. |
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
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
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
Summary
Both
grails-forgeCloud Run deploy workflows (Forge - Next GCP Deploy run 25514779324 and Forge - Prev Snapshot GCP Deploy run 25515077555) are currently failing at thedockerBuildNativestep 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:dockerBuildNativeThe Micronaut Gradle Application Plugin 4.6.2 transitively bundles the GraalVM Reachability Metadata Repository entry for
ch.qos.logback/logback-classicat metadata-version 1.4.9 (visible in the build log asconfig-dirs/ch.qos.logback/logback-classic/1.4.9). That entry marks the entirech.qos.logbackpackage 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:dockerBuildNativeThe
Args = --initialize-at-build-time=org.postgresql.Driver,org.postgresql.util.SharedTimerline innative-image.propertiesforcedorg.postgresql.Driverto initialize at build time, which transitively triggeredjava.sql.DriverManager.<clinit>to run at build time. Micronaut SQL registersjava.sql.DriverManagerfor run-time initialization, producing the conflict reported asjava.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), andmicronaut-jdbcalready ships--add-modules=java.sql.rowsetfor the rest of the JDBC support classes.Changes
grails-forge-web-netty/.../native-image.propertiesAdd
--initialize-at-run-time=ch.qos.logback,org.slf4jto override the bundled 1.4.9 build-time-init directive without touching reflection or resource configuration.grails-forge-analytics-postgres/.../native-image.propertiesDrop the manual
--initialize-at-build-time=org.postgresql.Driver,org.postgresql.util.SharedTimerand replace with the same logback runtime-init override (this module also hasruntimeOnly "ch.qos.logback:logback-classic:$logbackClassicVersion", so it will hit the same logback issue once the DriverManager error clears).Both files are now header-commented to explain why these flags exist, matching the style used in the
dockerfileNativeblock ingrails-forge-web-netty/build.gradleandgrails-forge-analytics-postgres/build.gradlefor the GraalVM image pin.Verification
./gradlew :grails-forge-web-netty:processResources :grails-forge-analytics-postgres:processResources(offline) → exit 0; bothnative-image.propertiesfiles load viajava.util.Properties.load(...)and produce the expectedArgsvalue.dockerBuildNativeand is best verified by re-triggering the twoworkflow_dispatchworkflows after this lands. RAT, code-style and the standardgradle.ymlbuild are unaffected because the changes are confined toMETA-INF/native-image/**/native-image.properties, which is excluded from RAT (seegradle/rat-root-config.gradle).References