Skip to content

make AOT hints for ELC optional#3267

Merged
sothawo merged 1 commit intospring-projects:mainfrom
rursprung:make-elc-aot-hints-optional
Mar 30, 2026
Merged

make AOT hints for ELC optional#3267
sothawo merged 1 commit intospring-projects:mainfrom
rursprung:make-elc-aot-hints-optional

Conversation

@rursprung
Copy link
Copy Markdown
Contributor

@rursprung rursprung commented Mar 26, 2026

spring-data-elasticsearch is also being pulled in as a dependency of spring-data-opensearch. the latter excludes the transient ELC dependency since it doesn't need it.
if spring-data-opensearch (or any downstream project) wants to use AOT then spring will automatically also pick up the AOT hints from spring-data-elasticsearch - but so far these reference the ELC classes which have been excluded by spring-data-opensearch, thus resulting in a ClassNotFoundException.

this commit makes the registration of these hints dependent on the presence of the ELC on the classpath. this has no impact on spring-data-elasticsearch consumers which already make use of AOT but unblocks the usage of AOT for spring-data-opensearch and its consumers.

see also opensearch-project/spring-data-opensearch#441

closes #3268

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our issue tracker. Add the issue number to the Closes #issue-number line below
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes. - there are no test cases for AOT in this project, however see the downstream PR on spring-data-opensearch with which i've tested this
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only). - this was a trivial change => no need to mention my name

`spring-data-elasticsearch` is also being pulled in as a dependency of
`spring-data-opensearch`. the latter excludes the transient ELC
dependency since it doesn't need it.
if `spring-data-opensearch` (or any downstream project) wants to use AOT
then spring will automatically also pick up the AOT hints from
`spring-data-elasticsearch` - but so far these reference the ELC classes
which have been excluded by `spring-data-opensearch`, thus resulting in
a `ClassNotFoundException`.

this commit makes the registration of these hints dependent on the
presence of the ELC on the classpath. this has no impact on
`spring-data-elasticsearch` consumers which already make use of AOT but
unblocks the usage of AOT for `spring-data-opensearch` and its
consumers.

see also opensearch-project/spring-data-opensearch#441

Signed-off-by: Ralph Ursprung <Ralph.Ursprung@avaloq.com>
@rursprung rursprung force-pushed the make-elc-aot-hints-optional branch from cd2dca2 to e4b7f62 Compare March 26, 2026 16:06
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 26, 2026
rursprung added a commit to rursprung/spring-data-opensearch that referenced this pull request 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).

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
rursprung added a commit to rursprung/spring-data-opensearch that referenced this pull request 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).

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>
rursprung added a commit to rursprung/spring-data-opensearch that referenced this pull request 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).

`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>
@rursprung
Copy link
Copy Markdown
Contributor Author

@rursprung rursprung marked this pull request as ready for review March 27, 2026 10:07
@sothawo sothawo merged commit ffdbea4 into spring-projects:main Mar 30, 2026
2 checks passed
@reta
Copy link
Copy Markdown
Contributor

reta commented Mar 30, 2026

Thanks a lot @sothawo !

@rursprung rursprung deleted the make-elc-aot-hints-optional branch March 31, 2026 06:45
@rursprung
Copy link
Copy Markdown
Contributor Author

thanks a lot @sothawo! do you see a chance to cherry-pick this to the 6.0.x branch (and get a fresh release off of there) so that we could already use it with Spring Boot 4.0.x rather than having to wait for SB 4.1.0?

@sothawo
Copy link
Copy Markdown
Collaborator

sothawo commented Mar 31, 2026

Thought you would ask that. Backported.

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

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make AOT hints for ELC optional

4 participants