Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraalVM Native Image support #403

Open
beckermarc opened this issue Aug 4, 2023 · 0 comments
Open

GraalVM Native Image support #403

beckermarc opened this issue Aug 4, 2023 · 0 comments

Comments

@beckermarc
Copy link

GraalVM Native Image support and tooling also allows to run tests in Native Image style (e.g. see docs of Spring Boot Native Image support).

As Hamcrest is a popular matcher library and Spring Boot includes Hamcrest for example in it's spring-boot-starter-test it is very likely that Hamcrest is also used in tests executed inside a GraalVM Native Image.

There are some areas where Hamcrest is relying on Java reflection most prominently through ReflectiveTypeFinder, which is used in various matcher implementations. Some of these reflection usages - but not all - can be known upfront in the library. GraalVM requires reflection usage to be registered in reflect-config.json files (see GraalVM docs here and here).

A good starting point that should suit many usecases already are reflection hints for the usages of ReflectiveTypeFinder.
Therefore my suggestion is to place the following reflect-config.json file, placed under hamcrest/src/main/resources/META-INF/native-image/org.hamcrest/hamcrest/

[
  {
    "condition": {
      "typeReachable": "org.hamcrest.TypeSafeMatcher"
    },
    "name": "org.hamcrest.TypeSafeMatcher",
    "queryAllDeclaredMethods": true
  },
  {
    "condition": {
      "typeReachable": "org.hamcrest.TypeSafeDiagnosingMatcher"
    },
    "name": "org.hamcrest.TypeSafeDiagnosingMatcher",
    "queryAllDeclaredMethods": true
  },
  {
    "condition": {
      "typeReachable": "org.hamcrest.FeatureMatcher"
    },
    "name": "org.hamcrest.FeatureMatcher",
    "queryAllDeclaredMethods": true
  }
]

As it is preferred to add GraalVM Native Image support to the libraries directly I wanted to ask, if there is willingness to add this configuration to Hamcrest? If not, an alternative solution would be to add the reflection hints to the community maintained GraalVM Reachability Metadata.

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

No branches or pull requests

1 participant