diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/native-image/testing-native-applications.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/native-image/testing-native-applications.adoc index 1ccefe199d..aafe2c7c38 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/native-image/testing-native-applications.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/native-image/testing-native-applications.adoc @@ -85,7 +85,9 @@ You should have a `` section that looks like this: ---- -The `spring-boot-starter-parent` declares a `nativeTest` profile that configures the executions that are needed to run the native tests. +The `spring-boot-starter-parent` defines a `nativeTest` profile that provides the necessary configuration for the Spring Boot and Native Build Tools plugins. +First you need to add those two plugin in the module to opt-in for the feature. +Your tests are executed in native mode only when the `nativeTest` is enabled. You can activate profiles using the `-P` flag on the command line. TIP: If you don't want to use `spring-boot-starter-parent` you'll need to configure executions for the `process-test-aot` goal from the Spring Boot plugin and the `test` goal from the Native Build Tools plugin. diff --git a/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle b/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle index f695fbfd61..1accf86dcf 100644 --- a/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle +++ b/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle @@ -306,31 +306,33 @@ publishing.publications.withType(MavenPublication) { } } build { - plugins { - plugin { - delegate.groupId('org.springframework.boot') - delegate.artifactId('spring-boot-maven-plugin') - executions { - execution { - delegate.id('process-test-aot') - goals { - delegate.goal('process-test-aot') + pluginManagement { + plugins { + plugin { + delegate.groupId('org.springframework.boot') + delegate.artifactId('spring-boot-maven-plugin') + executions { + execution { + delegate.id('process-test-aot') + goals { + delegate.goal('process-test-aot') + } } } } - } - plugin { - delegate.groupId('org.graalvm.buildtools') - delegate.artifactId('native-maven-plugin') - configuration { - delegate.classesDirectory('${project.build.outputDirectory}') - delegate.requiredVersion('22.3') - } - executions { - execution { - delegate.id('native-test') - goals { - delegate.goal('test') + plugin { + delegate.groupId('org.graalvm.buildtools') + delegate.artifactId('native-maven-plugin') + configuration { + delegate.classesDirectory('${project.build.outputDirectory}') + delegate.requiredVersion('22.3') + } + executions { + execution { + delegate.id('native-test') + goals { + delegate.goal('test') + } } } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/examples/aot-test/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/examples/aot-test/pom.xml deleted file mode 100644 index b20f0d0dcc..0000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/examples/aot-test/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - aot - - - - - org.springframework.boot - spring-boot-maven-plugin - - - process-test-aot - - process-test-aot - - - - - - - - - - diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/pages/aot.adoc b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/pages/aot.adoc index 442f2877bf..fcbec79dee 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/pages/aot.adoc +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/antora/modules/maven-plugin/pages/aot.adoc @@ -90,17 +90,33 @@ include::partial$goals/process-aot.adoc[leveloffset=+1] == 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 AOT engine in order to generate `ApplicationContextInitializer` code. +Those tests are processed by the AOT engine and are then executed in a native image. -To configure your application to use this feature, add an execution for the `process-test-aot` goal, as shown in the following example: +Just like <>, the `spring-boot-starter-parent` defines a `nativeTest` profile that can be used to streamline the steps required to execute your tests in a native image. + +The `nativeTest` profile configures the following: + +* Execution of `process-test-aot` when the Spring Boot Maven Plugin is applied on a project. +* Execution of `test` when the {url-native-build-tools-docs-maven-plugin}[Native Build Tools Maven Plugin] is applied on a project. +The execution defines sensible defaults, in particular: +** Making sure the plugin uses the raw classpath, and not the main jar file as it does not understand our repackaged jar format. +** Validate that a suitable GraalVM version is available. +** Download third-party reachability metadata. + +To benefit from the `nativeTest` profile, a module that represents an application should define two plugins, as shown in the following example: [source,xml,indent=0,subs="verbatim,attributes"] ---- -include::example$aot-test/pom.xml[tags=aot] +include::example$aot-native/pom.xml[tags=aot-native] ---- -TIP: If you are using `spring-boot-starter-parent`, this execution is automatically configured if you enable the `nativeTest` profile. +Once the above is in place for each module that needs this feature, you can build your multi-modules project and execute your tests in a native image in the relevant sub-modules, as shown in the following example: -As with application AOT processing, the `BeanFactory` is fully prepared at build-time. +[source,shell] +---- +$ mvn test -PnativeTest +---- + +NOTE: As with application AOT processing, the `BeanFactory` is fully prepared at build-time. include::partial$goals/process-test-aot.adoc[leveloffset=+1]