Skip to content

Support -H:+CompatibilityMode in build tools#822

Open
vjovanov wants to merge 14 commits intomasterfrom
vj/compatibility-mode
Open

Support -H:+CompatibilityMode in build tools#822
vjovanov wants to merge 14 commits intomasterfrom
vj/compatibility-mode

Conversation

@vjovanov
Copy link
Member

@vjovanov vjovanov commented Jan 21, 2026

When the Native Image Compatibility Mode flag is enabled (-H:+CompatibilityMode), the Maven native test goal is automatically short-circuited: native-image based JUnit tests are skipped and tests run on the JVM via Surefire/Failsafe instead.

  • What happens

    • If -H:+CompatibilityMode is detected, the native:test goal is skipped early and JVM tests execute (Surefire/Failsafe).
  • Detection sources

    • Effective native-image build arguments configured for the plugin/goal (e.g. -DbuildArgs=...).
    • Environment variable NATIVE_IMAGE_OPTIONS:
      • From the process environment.
      • From Surefire/Failsafe environment passed via plugin configuration (<environmentVariables>NATIVE_IMAGE_OPTIONS</environmentVariables>).
  • Behavior details

    • The native test goal returns early right after environment setup when Compatibility Mode is enabled.
    • The plugin logs once at INFO level with the exact text:
      • "Compatibility Mode detected (-H:+CompatibilityMode); skipping native-image test goal, JVM tests will run instead."
    • JVM tests still run normally; no extra configuration needed.
    • Default behavior is unchanged when the flag is absent; native-image tests run as before.
  • How to trigger and verify

    • CLI build args example:
      mvn -Pnative -DbuildArgs=-H:+CompatibilityMode test
    • Using NATIVE_IMAGE_OPTIONS:
      • Shell export:
        NATIVE_IMAGE_OPTIONS="-H:+CompatibilityMode" mvn -Pnative test
      • Or configure NATIVE_IMAGE_OPTIONS in the Surefire/Failsafe plugin environment within the POM.
    • Expected output:
      • The INFO log appears once with the exact text above.
      • No native-image build/run steps execute for the test goal.
      • JVM test results are reported by Surefire/Failsafe.
  • Resetting back to native tests

    • Remove -H:+CompatibilityMode from build args and ensure NATIVE_IMAGE_OPTIONS does not contain it.
  • References (implementation/tests)

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jan 21, 2026
@vjovanov vjovanov force-pushed the vj/compatibility-mode branch from a68e069 to e678a1f Compare January 21, 2026 12:45
@vjovanov vjovanov force-pushed the vj/compatibility-mode branch from 53f7072 to f999bc4 Compare January 29, 2026 08:30
“Compatibility Mode detected (-H:+CompatibilityMode); skipping native-image test build/run, JVM tests will run instead.”
* Maven: native test goal short-circuits after environment setup; once-per-build log:
+
“Compatibility Mode detected (-H:+CompatibilityMode); skipping native-image test goal, JVM tests will run instead.”
Copy link
Member Author

Choose a reason for hiding this comment

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

This is outdated.

command.add(xmlLocation.toString());
if (compatibilityMode) {
command.add("-cp=" + getClasspath());
command.add("--scan-classpath");
Copy link
Member Author

Choose a reason for hiding this comment

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

How to decide module-path or class-path?

…vider in Gradle

Added computeCompatibilityModeEnabledProvider and wired it to test options. Checks build args and NATIVE_IMAGE_OPTIONS env vars for -H:+CompatibilityMode.
…lper

Implements isCompatibilityModeEnabled() and invokes it after configureEnvironment() and before JUnitFeature wiring. Detection checks: buildArgs list, environment map NATIVE_IMAGE_OPTIONS, and System.getenv fallback for -H:+CompatibilityMode. Source plan: plans/fallback-compatibility-mode-junit.md.
…eateTestOptions)

Bead description: In createTestOptions, only set main class org.graalvm.junit.platform.NativeImageJUnitLauncher and --features=org.graalvm.junit.platform.JUnitPlatformFeature when !isCompatibilityModeEnabled; keep other wiring as-is.

Summary of work:

- Gate native JUnit launcher main class and JUnit Platform feature when Compatibility Mode is OFF.

- Detect Compatibility Mode via NATIVE_IMAGE_OPTIONS env, task env map, and task buildArgs.

- Preserve other test image wiring and behavior.

- Add functional test native-gradle-plugin/src/test/groovy/org/graalvm/buildtools/gradle/CompatibilityModeGatingTest.groovy.

- Fix Checkstyle variable naming.
…n Compatibility Mode

Bead description: Extend onlyIf predicates on test image builder and run tasks to require !isCompatibilityModeEnabled; log once using GraalVMLogger when disabling.

Summary of work:

- Reuse Provider-based Compatibility Mode detection to check -H:+CompatibilityMode from env and buildArgs.

- Skip native test image build/run tasks when Compatibility Mode is enabled with once-only info log.

- Centralize wiring in plugin; preserve other test wiring.

- Add functional tests for ON/OFF cases.
…tibility Mode

Bead description: After configureEnvironment() in execute(), if isCompatibilityModeEnabled() then log info and return early to skip native-image tests; retain skipTests/skipNativeTests/failNoTests behavior otherwise.

Summary of work:

- Add isCompatibilityModeEnabled() detection from build args and NATIVE_IMAGE_OPTIONS (env + surefire/failsafe env).

- Early return in NativeTestMojo.execute() with info log.

- Functional tests for OFF/ON via build args and NATIVE_IMAGE_OPTIONS.

- Minor Checkstyle whitespace fix.
…allback

Update native-gradle-plugin/README.md to document automatic fallback when -H:+CompatibilityMode is enabled: detection via buildArgs and NATIVE_IMAGE_OPTIONS; gating of native JUnit wiring; onlyIf-based skip of native test image build/run; once-per-build info log; how to trigger/verify and how to reset; default OFF behavior unchanged.
…allback

Update native-maven-plugin/README.md to document automatic fallback when -H:+CompatibilityMode is enabled: detection via buildArgs and NATIVE_IMAGE_OPTIONS; early return in NativeTestMojo.execute(); once-per-build info log; how to trigger/verify and how to reset; default OFF behavior unchanged.
Add Unreleased feature: Auto-fallback to JVM JUnit when -H:+CompatibilityMode is enabled.

Details:

- Disables native-image JUnit when the flag is present; JVM tests run automatically.

- Detection via build arguments and NATIVE_IMAGE_OPTIONS env var.

- Gradle: gate JUnit wiring, skip native test build/run via onlyIf, once-per-build info log.

- Maven: short-circuit native test goal after environment setup, once-per-build info log.

- Default behavior unchanged when flag is absent.
Bead native-build-tools-80s: Add 'plans/' to .gitignore to keep the working tree clean for subsequent tasks.
@vjovanov vjovanov force-pushed the vj/compatibility-mode branch from fd64919 to 87189e6 Compare February 16, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant