parent
e32c6cde72
commit
3082b0c5bf
@ -0,0 +1,43 @@
|
|||||||
|
[[aot]]
|
||||||
|
= Ahead-of-Time Processing
|
||||||
|
Spring AOT is a process that analyzes your code at build-time in order to generate an optimized version of it.
|
||||||
|
It is most often used to help generate GraalVM native images.
|
||||||
|
|
||||||
|
The Spring Boot Gradle plugin provides tasks that can be used to perform AOT processing on both application and test code.
|
||||||
|
The tasks are configured automatically when the {nbt-gradle-plugin}[GraalVM Native Image plugin] is applied:
|
||||||
|
|
||||||
|
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
|
||||||
|
.Groovy
|
||||||
|
----
|
||||||
|
include::../gradle/aot/apply-native-image-plugin.gradle[]
|
||||||
|
----
|
||||||
|
|
||||||
|
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
|
||||||
|
.Kotlin
|
||||||
|
----
|
||||||
|
include::../gradle/aot/apply-native-image-plugin.gradle.kts[]
|
||||||
|
----
|
||||||
|
|
||||||
|
|
||||||
|
[[aot.processing-applications]]
|
||||||
|
== Processing Applications
|
||||||
|
Based on your `@SpringBootApplication`-annotated main class, the `processAot` task generates a persistent view of the beans that are going to be contributed at runtime in a way that bean instantiation is as straightforward as possible.
|
||||||
|
Additional post-processing of the factory is possible using callbacks.
|
||||||
|
For instance, these are used to generate the necessary reflection configuration that GraalVM needs to initialize the context in a native image.
|
||||||
|
|
||||||
|
As the `BeanFactory` is fully prepared at build-time, conditions are also evaluated.
|
||||||
|
This has an important difference compared to what a regular Spring Boot application does at runtime.
|
||||||
|
For instance, if you want to opt-in or opt-out for certain features, you need to configure the environment used at build time to do so.
|
||||||
|
To this end, the `processAot` task is a {gradle-dsl}/org.gradle.api.tasks.JavaExec.html[`JavaExec`] task and can be configured with environment variables, system properties, and arguments as needed.
|
||||||
|
|
||||||
|
The `nativeCompile` task of the GraalVM Native Image plugin is automatically configured to use the output of the `processAot` task.
|
||||||
|
|
||||||
|
|
||||||
|
[[aot.processing-tests]]
|
||||||
|
== Processing Tests
|
||||||
|
The AOT engine can be applied to JUnit 5 tests that use Spring's Test Context Framework.
|
||||||
|
Suitable tests are processed by the `processTestAot` task to generate `ApplicationContextInitialzer` code.
|
||||||
|
As with application AOT processing, the `BeanFactory` is fully prepared at build-time.
|
||||||
|
As with `processAot`, the `processTestAot` task is `JavaExec` sub-class and can be configured as needed to influence this processing.
|
||||||
|
|
||||||
|
The `nativeTest` task of the GraalVM Native Image plugin is automatically configured to use the output of the `processAot` and `processTestAot` tasks.
|
@ -0,0 +1,5 @@
|
|||||||
|
plugins {
|
||||||
|
id 'org.springframework.boot' version '{gradle-project-version}'
|
||||||
|
id 'org.graalvm.buildtools.native' version '{native-build-tools-version}'
|
||||||
|
id 'java'
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.springframework.boot") version "{gradle-project-version}"
|
||||||
|
id("org.graalvm.buildtools.native") version "{native-build-tools-version}"
|
||||||
|
java
|
||||||
|
}
|
Loading…
Reference in New Issue