This project goal is to provide experimental support for building Spring Boot applications as GraalVM native images. Watch this Running Spring Boot applications as GraalVM native images Devoxx talk video for more details.
It is mainly composed of 6 parts:
-
spring-graal-native-feature
: this module is Spring GraalVM feature. A feature here is a GraalVM term meaning a plugin for the native-image compilation process (which creates the native-image from the built class files). The feature participates in the compilation lifecycle, being invoked at different compilation stages to offer extra information about the application to aid in the image construction. -
spring-graal-native-configuration
: this module contains configuration hints for Spring classes, including various Spring Boot auto-configurations. -
spring-graal-native-substitutions
: this module allows to patch temporarily some part of Spring Boot and Spring Framework to improve compatibility and efficiency of Spring native images. -
spring-graal-native
: this module aggregates the feature, configuration and substitutions ones to generate the artifact to consume. -
spring-graal-native-samples
: contains various samples that demonstrate the feature usage and are used as integration tests. -
spring-graal-native-docs
: contains the asciidoc documentation sources.
This project status is alpha, that means that we are currently mainly working on the software design and on supporting the features of the current samples (work in progress). Supporting a wider and clearly defined range of Spring Boot applications, as well as optimizing efficiency (image size, memory consumption) and performances will happen as a second step.
Spring team collaborates with GraalVM native team by raising issues in their bug tracker, with the goal to improve the production-readiness of native-images. These bugs on GraalVM issue tracker are identified by the spring
label.
For detailed information and walkthroughs of applying the techniques to your project, please see the documentation.
If you are using Docker based builds descried above, the right GraalVM distribution is already installed, you can skip this section.
From GraalVM builds:
Or you can use SDKMAN to easily switch between GraalVM versions:
-
Install GraalVM with
sdk install java 20.0.0.r8-grl
for Java 8 orsdk install java 20.0.0.r11-grl
for Java 11 -
Run
gu install native-image
to bring in the native-image extensions to the JDK.
The latest 0.6.1.RELEASE release supports GraalVM 20.0.0 and Spring Boot 2.3.0.M4.
-
Download and extract sources from the latest release.
-
Go into the samples folder and pick one (e.g.
cd spring-graal-native-samples/commandlinerunner
) -
Run
./build.sh
which will run a maven build, then a native image compile, then test the result.
build.sh
runs the compile.sh
script and in that compile script you can see the invocation of the native-image
command. The other samples follow a similar model. For more details on the samples see the samples documentation.
This project is in the spring-projects-experimental
org indicating it is not as mature as other Spring projects. Contributions are welcome (maybe read the extension guide if thinking about extending it to support your project). However, please recognize we aren’t at the polishing javadoc stage and whilst pre 1.0 there may be heavy evolution of APIs.
The development version on master
is currently based on GraalVM 20.1-dev and Spring Boot 2.3.0.M4.
Mac and Linux are supported, Windows in untested.
In order to allow easily reproducible builds of spring-graal-native
, dedicated interactive Docker images are available for local development (and are also used in the CI).
To use it:
-
Configure it to allow non-root user if you are on Linux.
-
Run
docker/build-dev-images.sh
to build thespring-graal-native-dev
Docker images dedicated for development, they are based (multi-stage builds) on thegraalvm-ce
andspring-graal-native
images built on the CI. -
You can now invoke
docker/run-20.1-dev-java8.sh
ordocker/run-20.1-dev-java11.sh
to run the Docker container with an interactive shell suitable to runspring-graal-native
build scripts (see "Usual dev workflow" section bellow for more details). -
The
spring-graal-native
directory and the Maven home directory are shared between the host (where is typically the IDE) and the container (where you can run builds).
-
Import the root project in your IDE.
-
Eventually import the sample you are working on as a distinct project in your IDE.
-
Follow instructions from the "Use Docker based build environment" section above.
-
Run the root project
build.sh
(from the host or the container) if you have made modification to the feature, substitutions or configuration modules. -
Run
build.sh
of the sample you are working on from the container.
To test the various samples You can also run the root build.sh
then build-key-samples.sh
(test only key samples) or build-samples.sh
(test all samples) from the container.