Skip to content

Support -H:+CompatibilityMode in build tools#822

Merged
vjovanov merged 1 commit intomasterfrom
vj/compatibility-mode
Feb 26, 2026
Merged

Support -H:+CompatibilityMode in build tools#822
vjovanov merged 1 commit intomasterfrom
vj/compatibility-mode

Conversation

@vjovanov
Copy link
Copy Markdown
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.

@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
Comment thread docs/src/docs/asciidoc/changelog.adoc Outdated
Copy link
Copy Markdown
Member

@jormundur00 jormundur00 left a comment

Choose a reason for hiding this comment

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

Currently, all the tests fail due to the missing -H:+CompatibilityMode option, so I believe we should at least wait until it exists in the latest GraalVM JDK.

Other than that, when locally running with a JDK that has this option, both the gradle and maven tests fail with:

    > Task :nativeTest
     FAILED

    7 actionable tasks: 7 executed


CompatibilityModeNativeTestsFunctionalTest > ON via NATIVE_IMAGE_OPTIONS env map: native test image build/run are skipped and message logged FAILED
    org.spockframework.runtime.ConditionFailedWithExceptionError at CompatibilityModeNativeTestsFunctionalTest.groovy:107
        Caused by: org.codehaus.groovy.runtime.powerassert.PowerAssertionError at CompatibilityModeNativeTestsFunctionalTest.groovy:108

which, if I understand the point of this PR, is because nativeTest should be skipped and isn't?

import spock.lang.Requires
import spock.lang.Specification

@Requires({ JavaVersion.current().isCompatibleWith(JavaVersion.toVersion(25)) })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This points to the JAVA_HOME used by the gradle wrapper, and not the GRAALVM_HOME, so the tests get skipped when attempting to run with JAVA_HOME set as JDK 17 (for the gradle), and GRAALVM_HOME set as JDK 25 (for the image build). I think we should use @Requires({ NativeImageUtils.getMajorJDKVersion(GraalVMSupport.getGraalVMHomeVersionString()) >= 25 }) like it's done in LayeredApplicationFunctionalTest here (also to stay consistent with the Maven test. that runs properly with this setup).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I removed all the tests for now.

@vjovanov vjovanov force-pushed the vj/compatibility-mode branch from bcf620c to 2182f42 Compare February 23, 2026 13:35
In compatibility mode JUnit tests are executed like on the JVM.
@vjovanov vjovanov force-pushed the vj/compatibility-mode branch from 2182f42 to 0631241 Compare February 25, 2026 13:03
@vjovanov vjovanov merged commit 790fa05 into master Feb 26, 2026
567 checks passed
@vjovanov vjovanov deleted the vj/compatibility-mode branch February 26, 2026 12:19
mergify Bot added a commit to robfrank/linklift that referenced this pull request Mar 10, 2026
…1.4 to 0.11.5 [skip ci]

Bumps [org.graalvm.buildtools:native-maven-plugin](https://github.com/graalvm/native-build-tools) from 0.11.4 to 0.11.5.
Release notes

*Sourced from [org.graalvm.buildtools:native-maven-plugin's releases](https://github.com/graalvm/native-build-tools/releases).*

> 0.11.5
> ------
>
> What's Changed
> --------------
>
> * Bump version to 0.11.5-SNAPSHOT by [`@​graalvmbot`](https://github.com/graalvmbot) in [graalvm/native-build-tools#817](https://redirect.github.com/graalvm/native-build-tools/pull/817)
> * Make environment variables set in the pom.xml of the native-maven-plugin be visible in the image builder by [`@​jormundur00`](https://github.com/jormundur00) in [graalvm/native-build-tools#819](https://redirect.github.com/graalvm/native-build-tools/pull/819)
> * Add check if correct schemas are present in the reachability metadata repository provided to buildtools by [`@​jormundur00`](https://github.com/jormundur00) in [graalvm/native-build-tools#821](https://redirect.github.com/graalvm/native-build-tools/pull/821)
> * Add fallback for jarless artifacts in the native-maven-plugin by [`@​jormundur00`](https://github.com/jormundur00) in [graalvm/native-build-tools#824](https://redirect.github.com/graalvm/native-build-tools/pull/824)
> * Fix JUnit 6 not working correctly with JDK 21 by expanding the initialize-at-build-time-list by [`@​jormundur00`](https://github.com/jormundur00) in [graalvm/native-build-tools#832](https://redirect.github.com/graalvm/native-build-tools/pull/832)
> * Remove the usage of the global metadata/index.json from the nbt plugins by [`@​jormundur00`](https://github.com/jormundur00) in [graalvm/native-build-tools#829](https://redirect.github.com/graalvm/native-build-tools/pull/829)
> * Revert "Remove the usage of the global metadata/index.json from the nbt plugins" by [`@​jormundur00`](https://github.com/jormundur00) in [graalvm/native-build-tools#836](https://redirect.github.com/graalvm/native-build-tools/pull/836)
> * Use JDK 21 Graal in the CI by [`@​jormundur00`](https://github.com/jormundur00) in [graalvm/native-build-tools#839](https://redirect.github.com/graalvm/native-build-tools/pull/839)
> * Support `-H:+CompatibilityMode` in build tools by [`@​vjovanov`](https://github.com/vjovanov) in [graalvm/native-build-tools#822](https://redirect.github.com/graalvm/native-build-tools/pull/822)
> * Update reachability metadata to 0.3.34 by [`@​graalvmbot`](https://github.com/graalvmbot) in [graalvm/native-build-tools#842](https://redirect.github.com/graalvm/native-build-tools/pull/842)
>
> **Full Changelog**: <graalvm/native-build-tools@0.11.4...0.11.5>


Commits

* [`ffd094d`](graalvm/native-build-tools@ffd094d) Release 0.11.5
* [`1d7c2f7`](graalvm/native-build-tools@1d7c2f7) Merge pull request [#842](https://redirect.github.com/graalvm/native-build-tools/issues/842) from graalvm/update-metadata-to-0.3.34
* [`ba1c2e8`](graalvm/native-build-tools@ba1c2e8) Update reachability metadata to 0.3.34
* [`790fa05`](graalvm/native-build-tools@790fa05) Merge pull request [#822](https://redirect.github.com/graalvm/native-build-tools/issues/822) from graalvm/vj/compatibility-mode
* [`0631241`](graalvm/native-build-tools@0631241) Implement Compatibility Mode detection
* [`1844654`](graalvm/native-build-tools@1844654) Use JDK 21 Graal in the CI ([#839](https://redirect.github.com/graalvm/native-build-tools/issues/839))
* [`6315677`](graalvm/native-build-tools@6315677) Revert "Remove the usage of the global metadata/index.json from the nbt plugi...
* [`fe065ce`](graalvm/native-build-tools@fe065ce) Remove the usage of the global metadata/index.json from the nbt plugins ([#829](https://redirect.github.com/graalvm/native-build-tools/issues/829))
* [`94b5b54`](graalvm/native-build-tools@94b5b54) Fix JUnit 6 not working correctly with JDK 21 by expanding the initialize-at-...
* [`086cfdf`](graalvm/native-build-tools@086cfdf) Add fallback for jarless artifacts in the native-maven-plugin ([#824](https://redirect.github.com/graalvm/native-build-tools/issues/824))
* Additional commits viewable in [compare view](graalvm/native-build-tools@0.11.4...0.11.5)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.graalvm.buildtools:native-maven-plugin&package-manager=maven&previous-version=0.11.4&new-version=0.11.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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.

2 participants