Skip to content

add AOT & native image support#638

Draft
rursprung wants to merge 1 commit intoopensearch-project:mainfrom
rursprung:add-aot-support
Draft

add AOT & native image support#638
rursprung wants to merge 1 commit intoopensearch-project:mainfrom
rursprung:add-aot-support

Conversation

@rursprung
Copy link
Copy Markdown
Contributor

@rursprung rursprung commented Mar 26, 2026

this registers the necessary hints for Ahead-of-Time Processing to support both AOT and GraalVM Native Image usage. it also modifies one example application so that it can - optionally - be run as a native image to show that it works. this is also used in CI to test that it still builds.

on its own this will fail since by using AOT we automatically also pull in the AOT hints registered in spring-data-elasticsearch which in turn currently unconditionally registers hints for the Elasticsearch Client (ELC) which we however exclude as a transient dependency. thus a PR has been raised to make this optional: spring-projects/spring-data-elasticsearch#3267 this will have to be merged & released first for this PR to work.

i have however verified things locally (though admittedly on the previous major release since i only had GraalVM 21 at hand and SB 4.x requires GraalVM 25).

Issues Resolved

resolves #411

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

* Runtime hints for Spring Data OpenSearch core functionality.
* Registers Spring Data callbacks and entity mapping classes.
*
* @since 3.0.4
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added the @since since i presume that this is still used here, even though most versions are from when it was copied away from spring-data-elasticsearch and thus the @since annotations IMHO don't make too much sense?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

3.1.0

alias(pluginLibs.plugins.spotless)
alias(pluginLibs.plugins.editorconfig)
id("java-conventions")
id("org.graalvm.buildtools.native") version "0.11.5"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

v1.0.0 is already released on their github repo but not yet available on the gradle repos. by the time this PR is ready we can probably directly go with v1.0.0.

open question: should this version be defined in the central settings.gradle.kts as well?

Copy link
Copy Markdown
Collaborator

@reta reta Mar 26, 2026

Choose a reason for hiding this comment

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

open question: should this version be defined in the central settings.gradle.kts as well?

We need it in one place for now, right? May not be worth settings.gradle.kts

graalvmNative {
binaries {
named("main") {
sharedLibrary.set(false)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the standard examples for the Gradle+Spring Boot+GraalVM combination don't usually include this block, but without setting sharedLibrary.set(false) i never got a binary - i just got a library and thus couldn't run nativeRun.

i'm happy to remove this if anyone figures out what's causing this (this is my first time working with GraalVM)

this registers the necessary hints for [Ahead-of-Time Processing] to
support both AOT and [GraalVM Native Image] usage. it also modifies one
example application so that it can - optionally - be run as a native
image to show that it works. this is also used in CI to test that it
still builds.

on its own this will fail since by using AOT we automatically also pull
in the AOT hints registered in `spring-data-elasticsearch` which in turn
currently unconditionally registers hints for the Elasticsearch Client
(ELC) which we however exclude as a transient dependency. thus a PR has
been raised to make this optional: spring-projects/spring-data-elasticsearch#3267
this will have to be merged & released first for this PR to work.

i have however verified things locally (though admittedly on the
previous major release since i only had GraalVM 21 at hand and SB 4.x
requires GraalVM 25).

`ElasticsearchClientAutoConfiguration` also needs to be excluded in the
`MarketplaceApplication` since otherwise two `JacksonJsonpMapper` beans
will be present and the application will fail to start in the
`processAot` phase.

resolves opensearch-project#411

[Ahead-of-Time Processing]: https://docs.spring.io/spring-boot/reference/packaging/aot.html
[GraalVM Native Image]: https://docs.spring.io/spring-boot/reference/packaging/native-image/index.html

Signed-off-by: Ralph Ursprung <Ralph.Ursprung@avaloq.com>
* Runtime hints for OpenSearch Java client library.
* `opensearch-java` does not provide its own hints since this is Spring-specific.
*
* @since 3.0.4
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To my knowledge, there won't be any bugports to Spring Data Elasticsearch 6.0.x (only bugfixes), if the change on its side lands (🙏 ), we will be able to use in in 6.1.0 only

Suggested change
* @since 3.0.4
* @since 3.1.0

/**
* Runtime hints for Spring Data OpenSearch repository implementations.
*
* @since 3.0.4
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* @since 3.0.4
* @since 3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants