Skip to content

Dapr Java SDK Support For GraalVM #818

Open
@rahulpoddar-fyndna

Description

@rahulpoddar-fyndna

We started looking into graalVM support with spring 3.0 release (part of Spring Framework 6.0 released recently)

In order to adopt Spring native (rather native image), we have to do the following.
To support native image we need to upgrade to Spring framework 6.0 which also has spring boot 3. Spring boot 3 is the version which has first class support for native.

Spring Boot 3 needs JDK 17. For AOT , we have to use GraalVM - version 23

With this the java enterprise edition has moved to Jakarta enterprise edition and this needs some code changes as well.Specifically all the javax namespace has moved to Jakarta namespace.

In case we use httpclient library then it has to be moved to httpclient5. This is being used in governor application and need to be sure to change if used elsewhere in product.

While doing a build with gradle, we have to be sure to provide the list of classes which cannot be instantiated during the build time. io.grpce and log4j being some of the classes. Appropriate configuration has to be done to avoid initialisation at build time.

The underlying libraries need to support spring native.
Some of the main reasons are as follows
A. For graalvm to create native binaries the classes to be accessed by name at runtime must be known at build time.
B. Individual classes, methods, and fields that should be accessible via reflection must be known to the native-image tool at build time

  Point B above is know only to the library is known only to the developer of the library and for graalVM to work, the library may have to provide hints in terms of json       configurations / gradle build argument (or maven)

What we tried
We made all the changes in our code as per recommendations from GraalVM and Spring native. We were able to crated native binary. We noticed that application fails at the start as it is not able to initialize dapr client. I am attaching the txt file (dapr_client_error.txt) having stack trace.
dapr_client_error.txt

Support for Dapr SDK Compliant with JDK17/ graalVM
As covered in the first part all third party library will have to comply with the latest changes so that consuming application can adopt spring native.
The migration activity can be two parts

  1. Support JDK 17.
  2. Adopt graalVM
    Blogs which can be referred for further details
    https://www.baeldung.com/spring-boot-3-spring-6-new

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions