diff --git a/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/examples/aot/apply-aot-plugin.gradle b/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/examples/aot/apply-aot-plugin.gradle new file mode 100644 index 00000000000..89d257ab1cf --- /dev/null +++ b/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/examples/aot/apply-aot-plugin.gradle @@ -0,0 +1,6 @@ +plugins { + id 'org.springframework.boot' version '{version-spring-boot}' + id 'java' +} + +apply plugin: 'org.springframework.boot.aot' diff --git a/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/examples/aot/apply-aot-plugin.gradle.kts b/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/examples/aot/apply-aot-plugin.gradle.kts new file mode 100644 index 00000000000..5a1a0884e26 --- /dev/null +++ b/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/examples/aot/apply-aot-plugin.gradle.kts @@ -0,0 +1,6 @@ +plugins { + id("org.springframework.boot") version "{version-spring-boot}" + java +} + +apply(plugin = "org.springframework.boot.aot") diff --git a/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/pages/aot.adoc b/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/pages/aot.adoc index ee631e308f7..d1e40fae0ba 100644 --- a/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/pages/aot.adoc +++ b/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/pages/aot.adoc @@ -4,8 +4,8 @@ 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 {url-native-build-tools-docs-gradle-plugin}[GraalVM Native Image plugin] is applied: +The `org.springframework.boot.aot` Gradle plugin provides tasks that can be used to perform AOT processing on both application and test code. +The plugin is applied automatically when the {url-native-build-tools-docs-gradle-plugin}[GraalVM Native Image plugin] is applied: [tabs] ====== @@ -23,6 +23,24 @@ include::example$aot/apply-native-image-plugin.gradle.kts[] ---- ====== +If you want to xref:reference:packaging/aot.adoc[run an AOT-processed application on the JVM] rather than as a native image, apply the `org.springframework.boot.aot` plugin directly: + +[tabs] +====== +Groovy:: ++ +[source,groovy,indent=0,subs="verbatim,attributes"] +---- +include::example$aot/apply-aot-plugin.gradle[] +---- +Kotlin:: ++ +[source,kotlin,indent=0,subs="verbatim,attributes"] +---- +include::example$aot/apply-aot-plugin.gradle.kts[] +---- +====== + [[aot.processing-applications]] diff --git a/build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/AotDocumentationTests.java b/build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/AotDocumentationTests.java new file mode 100644 index 00000000000..54beb9af816 --- /dev/null +++ b/build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/AotDocumentationTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.gradle.docs; + +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.gradle.junit.GradleMultiDslExtension; +import org.springframework.boot.testsupport.gradle.testkit.GradleBuild; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for AOT documentation. + * + * @author Andy Wilkinson + */ +@ExtendWith(GradleMultiDslExtension.class) +class AotDocumentationTests { + + @SuppressWarnings("NullAway.Init") + GradleBuild gradleBuild; + + @TestTemplate + void applyNativeImagePlugin() { + assertThat(this.gradleBuild.script(Examples.DIR + "aot/apply-native-image-plugin").build("tasks").getOutput()) + .contains("nativeCompile") + .contains("aotClasses"); + } + + @TestTemplate + void applyAotPlugin() { + assertThat(this.gradleBuild.script(Examples.DIR + "aot/apply-aot-plugin").build("tasks").getOutput()) + .contains("aotClasses") + .doesNotContain("nativeCompile"); + } + +}