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 fcbec79deef..5e92a89f746 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 @@ -92,6 +92,8 @@ include::partial$goals/process-aot.adoc[leveloffset=+1] The AOT engine can be applied to JUnit 5 tests that use Spring's Test Context Framework. Those tests are processed by the AOT engine and are then executed in a native image. +NOTE: Tests are not processed when the regular tests are skipped using the `maven.test.skip` property. + 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: diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java index 49bb6ec7bca..602c1253feb 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java @@ -198,6 +198,16 @@ class AotTests { }); } + @TestTemplate + void whenTestAotRunsWithTestSkipItIsAlsoSkipped(MavenBuild mavenBuild) { + mavenBuild.project("aot-test-skip").goals("test").execute((project) -> { + Path aotDirectory = project.toPath().resolve("target/spring-aot/test"); + assertThat(aotDirectory).doesNotExist(); + Path testClassesDirectory = project.toPath().resolve("target/test-classes"); + assertThat(testClassesDirectory.resolve("META-INF").resolve("native-image")).doesNotExist(); + }); + } + List collectRelativePaths(Path sourceDirectory) { try (Stream pathStream = Files.walk(sourceDirectory)) { return pathStream.filter(Files::isRegularFile) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-test-skip/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-test-skip/pom.xml new file mode 100644 index 00000000000..e10124f2bfd --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-test-skip/pom.xml @@ -0,0 +1,67 @@ + + + 4.0.0 + org.springframework.boot.maven.it + aot-test-skip + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + @java.version@ + @java.version@ + true + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + process-test-aot + + + + + + + + + org.springframework.boot + spring-boot + @project.version@ + + + jakarta.servlet + jakarta.servlet-api + @jakarta-servlet.version@ + provided + + + org.springframework + spring-test + @spring-framework.version@ + test + + + org.springframework.boot + spring-boot-test + @project.version@ + test + + + org.assertj + assertj-core + @assertj.version@ + test + + + org.junit.jupiter + junit-jupiter + @junit-jupiter.version@ + test + + + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-test-skip/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-test-skip/src/main/java/org/test/SampleApplication.java new file mode 100644 index 00000000000..ee3c16b77dc --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-test-skip/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,29 @@ +/* + * 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.test; + +import org.springframework.boot.SpringApplication; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +public class SampleApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleApplication.class, args); + } + +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-test-skip/src/test/java/org/test/SampleApplicationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-test-skip/src/test/java/org/test/SampleApplicationTests.java new file mode 100644 index 00000000000..436f6c87806 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-test-skip/src/test/java/org/test/SampleApplicationTests.java @@ -0,0 +1,53 @@ +/* + * 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.test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +@SpringJUnitConfig +class SampleApplicationTests { + + @Autowired + private MyBean myBean; + + @Test + void contextLoads() { + assertThat(this.myBean).isNotNull(); + } + + @Configuration + static class MyConfig { + + @Bean + MyBean myBean() { + return new MyBean(); + } + + } + + static class MyBean { + + } + +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessTestAotMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessTestAotMojo.java index 8cf523bdf11..7b70a13d5ea 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessTestAotMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessTestAotMojo.java @@ -118,7 +118,7 @@ public class ProcessTestAotMojo extends AbstractAotMojo { getLog().debug("process-test-aot goal could not be applied to pom project."); return; } - if (Boolean.getBoolean("skipTests") || Boolean.getBoolean("maven.test.skip")) { + if (Boolean.getBoolean("maven.test.skip")) { getLog().info("Skipping AOT test processing since tests are skipped"); return; }