Skip to content

Commit 3082b0c

Browse files
committed
Add a section on AOT to the Gradle plugin's docs
Closes gh-32750
1 parent e32c6cd commit 3082b0c

File tree

6 files changed

+66
-3
lines changed

6 files changed

+66
-3
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ task asciidoctorPdf(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) {
9797
}
9898
}
9999

100+
tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
101+
attributes "native-build-tools-version": nativeBuildToolsVersion
102+
}
103+
100104
javadoc {
101105
options {
102106
author = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[[aot]]
2+
= Ahead-of-Time Processing
3+
Spring AOT is a process that analyzes your code at build-time in order to generate an optimized version of it.
4+
It is most often used to help generate GraalVM native images.
5+
6+
The Spring Boot Gradle plugin provides tasks that can be used to perform AOT processing on both application and test code.
7+
The tasks are configured automatically when the {nbt-gradle-plugin}[GraalVM Native Image plugin] is applied:
8+
9+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
10+
.Groovy
11+
----
12+
include::../gradle/aot/apply-native-image-plugin.gradle[]
13+
----
14+
15+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
16+
.Kotlin
17+
----
18+
include::../gradle/aot/apply-native-image-plugin.gradle.kts[]
19+
----
20+
21+
22+
[[aot.processing-applications]]
23+
== Processing Applications
24+
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.
25+
Additional post-processing of the factory is possible using callbacks.
26+
For instance, these are used to generate the necessary reflection configuration that GraalVM needs to initialize the context in a native image.
27+
28+
As the `BeanFactory` is fully prepared at build-time, conditions are also evaluated.
29+
This has an important difference compared to what a regular Spring Boot application does at runtime.
30+
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.
31+
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.
32+
33+
The `nativeCompile` task of the GraalVM Native Image plugin is automatically configured to use the output of the `processAot` task.
34+
35+
36+
[[aot.processing-tests]]
37+
== Processing Tests
38+
The AOT engine can be applied to JUnit 5 tests that use Spring's Test Context Framework.
39+
Suitable tests are processed by the `processTestAot` task to generate `ApplicationContextInitialzer` code.
40+
As with application AOT processing, the `BeanFactory` is fully prepared at build-time.
41+
As with `processAot`, the `processTestAot` task is `JavaExec` sub-class and can be configured as needed to influence this processing.
42+
43+
The `nativeTest` task of the GraalVM Native Image plugin is automatically configured to use the output of the `processAot` and `processTestAot` tasks.

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/index.adoc

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ v{gradle-project-version}
3939
:buildpacks-reference: https://buildpacks.io/docs
4040
:paketo-reference: https://paketo.io/docs
4141
:paketo-java-reference: {paketo-reference}/buildpacks/language-family-buildpacks/java
42-
:nbt-gradle-plugin: https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html
42+
:nbt-gradle-plugin: https://graalvm.github.io/native-build-tools/{native-build-tools-version}/gradle-plugin.html
4343

4444

4545

@@ -57,6 +57,8 @@ include::publishing.adoc[leveloffset=+1]
5757

5858
include::running.adoc[leveloffset=+1]
5959

60+
include::aot.adoc[leveloffset=+1]
61+
6062
include::integrating-with-actuator.adoc[leveloffset=+1]
6163

6264
include::reacting.adoc[leveloffset=+1]

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/reacting.adoc

+6-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ When Gradle's {application-plugin}[`application` plugin] is applied to a project
7070
When the {nbt-gradle-plugin}[GraalVM Native Image plugin] is applied to a project, the Spring Boot plugin:
7171

7272
. Applies the `org.springframework.boot.aot` plugin that:
73-
.. Registers a `ProcessAot` task named `processAot` that will generate AOT-optimized source code for the application.
73+
.. Registers `aot` and `aotTest` source sets.
74+
.. Registers a `ProcessAot` task named `processAot` that will generate AOT-optimized source for the application in the `aot` source set.
7475
.. Configures the Java compilation and process resources tasks for the `aot` source set to depend upon `processAot`.
75-
. Adds the output of the `aot` source set to the classpath of the `nativeCompile` task.
76+
.. Registers a `ProcessTestAot` task named `processTestAot` that will generated AOT-optimized source for the application's tests in the `aotTest` source set.
77+
.. Configures the Java compilation and process resources tasks for the `aotTest` source set to depend upon `processTestAot`.
78+
. Adds the output of the `aot` source set to the classpath of the `main` GraalVM native binary.
79+
. Adds the output of the `aotTest` source set to the classpath of the `test` GraalVM native binary.
7680
. Configures the GraalVM extension to disable Toolchain detection.
7781

7882

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
plugins {
2+
id 'org.springframework.boot' version '{gradle-project-version}'
3+
id 'org.graalvm.buildtools.native' version '{native-build-tools-version}'
4+
id 'java'
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
plugins {
2+
id("org.springframework.boot") version "{gradle-project-version}"
3+
id("org.graalvm.buildtools.native") version "{native-build-tools-version}"
4+
java
5+
}

0 commit comments

Comments
 (0)