Add support for invoking AOT to the Maven Plugin

This commit adds an `aot-generate` goal to the Maven Plugin that
triggers AOT generation on the application. The new goal shares a
number of properties with the existing `run` goal and uses the same
algorithm to detect the main class to use.

Closes gh-30525
This commit is contained in:
Stephane Nicoll
2022-03-30 19:40:01 +02:00
committed by Andy Wilkinson
parent 096420cc4c
commit e81c6337c6
12 changed files with 581 additions and 105 deletions

View File

@@ -0,0 +1,22 @@
[[aot]]
= Optimizing Your Application at Build-Time
Spring AOT inspects an application at build-time and generates an optimized version of it.
Based on your `@SpringBootApplication`-annotated main class, the AOT engine 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.
To configure your application to use this feature, add an execution for the `aot-generate` goal, as shown in the following example:
[source,xml,indent=0,subs="verbatim,attributes",tabsize=4]
----
include::../maven/aot/pom.xml[tags=aot]
----
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.
The `aot-generate` goal shares a number of properties with the <<run,run goal>> for that reason.
include::goals/aot-generate.adoc[leveloffset=+1]

View File

@@ -36,6 +36,8 @@ include::packaging-oci-image.adoc[leveloffset=+1]
include::running.adoc[leveloffset=+1]
include::aot.adoc[leveloffset=+1]
include::integration-tests.adoc[leveloffset=+1]
include::build-info.adoc[leveloffset=+1]

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>aot</artifactId>
<build>
<plugins>
<!-- tag::aot[] -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>aot-generate</id>
<goals>
<goal>aot-generate</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- end::aot[] -->
</plugins>
</build>
</project>