Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 5, 2025

Native-image build failed because org.junit.jupiter.engine.discovery.MethodSegmentResolver was initialized at build time instead of runtime.

Changes

  • Added --initialize-at-run-time argument to native-maven-plugin configuration in nitrite-native-tests/pom.xml
<configuration>
    <classesDirectory>${project.build.outputDirectory}</classesDirectory>
    <buildArgs>
        <buildArg>--initialize-at-run-time=org.junit.jupiter.engine.discovery.MethodSegmentResolver</buildArg>
    </buildArgs>
</configuration>

Fixes job 54394718335 (ref: 71b6cf0)

Original prompt

Problem:
The GitHub Actions run for PR 1187 failed in the native-image test phase with the following error (job ref: 71b6cf0, job id 54394718335):

Error: Classes that should be initialized at run time got initialized during image building:
org.junit.jupiter.engine.discovery.MethodSegmentResolver was unintentionally initialized at build time.

Root cause:
GraalVM native-image initialized a JUnit Jupiter class during image build. The native-image build must be instructed to initialize this class at runtime.

Solution (requested by user, "Use the solution number 1"):
Add the native-image argument to initialize the problematic class at run time:

--initialize-at-run-time=org.junit.jupiter.engine.discovery.MethodSegmentResolver

What to change:

  1. Update the native-maven-plugin configuration for the native tests module (nitrite-native-tests) to pass the above argument to native-image.

Specifically, add the following to the plugin config in nitrite-native-tests/pom.xml (or the module pom that configures org.graalvm.buildtools:native-maven-plugin):

org.graalvm.buildtools native-maven-plugin --initialize-at-run-time=org.junit.jupiter.engine.discovery.MethodSegmentResolver
  1. Ensure the plugin configuration retains any existing args and other settings.
  2. Run mvn -Pnative test (or the repository's native test profile) to verify the native-image build passes.

Notes:

  • If additional classes are reported in future runs, they can be appended as a comma-separated list in the same argument.
  • This change targets only build-time initialization behavior and should not affect runtime semantics beyond how native-image initializes those classes.

Please create a pull request that updates the pom for the nitrite-native-tests module with the above change, leaving other code untouched. Include a concise commit message and PR description referencing the failing job id and explaining the change.

This pull request was created as a result of the following prompt from Copilot chat.

Problem:
The GitHub Actions run for PR 1187 failed in the native-image test phase with the following error (job ref: 71b6cf0, job id 54394718335):

Error: Classes that should be initialized at run time got initialized during image building:
org.junit.jupiter.engine.discovery.MethodSegmentResolver was unintentionally initialized at build time.

Root cause:
GraalVM native-image initialized a JUnit Jupiter class during image build. The native-image build must be instructed to initialize this class at runtime.

Solution (requested by user, "Use the solution number 1"):
Add the native-image argument to initialize the problematic class at run time:

--initialize-at-run-time=org.junit.jupiter.engine.discovery.MethodSegmentResolver

What to change:

  1. Update the native-maven-plugin configuration for the native tests module (nitrite-native-tests) to pass the above argument to native-image.

Specifically, add the following to the plugin config in nitrite-native-tests/pom.xml (or the module pom that configures org.graalvm.buildtools:native-maven-plugin):

org.graalvm.buildtools native-maven-plugin --initialize-at-run-time=org.junit.jupiter.engine.discovery.MethodSegmentResolver
  1. Ensure the plugin configuration retains any existing args and other settings.
  2. Run mvn -Pnative test (or the repository's native test profile) to verify the native-image build passes.

Notes:

  • If additional classes are reported in future runs, they can be appended as a comma-separated list in the same argument.
  • This change targets only build-time initialization behavior and should not affect runtime semantics beyond how native-image initializes those classes.

Please create a pull request that updates the pom for the nitrite-native-tests module with the above change, leaving other code untouched. Include a concise commit message and PR description referencing the failing job id and explaining the change.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Note

Free review on us!

CodeRabbit is offering free reviews until Thu Nov 06 2025 to showcase some of the refinements we've made.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI changed the title [WIP] Update native-image configuration for JUnit initialization Fix native-image build: initialize JUnit MethodSegmentResolver at runtime Nov 5, 2025
Copilot AI requested a review from anidotnet November 5, 2025 19:12
@anidotnet anidotnet marked this pull request as ready for review November 5, 2025 19:29
Copilot AI review requested due to automatic review settings November 5, 2025 19:29
Copy link
Contributor

Copilot AI left a comment

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 configures GraalVM native image build arguments for the JUnit test engine to address runtime initialization issues. The change adds a specific build argument to defer initialization of JUnit's MethodSegmentResolver class until runtime, which is a common requirement for GraalVM native image compatibility with JUnit 5.

Key Changes

  • Added GraalVM native image build configuration to defer initialization of JUnit's MethodSegmentResolver class to runtime

@anidotnet anidotnet merged commit f8614a0 into main Nov 6, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants