diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/aot/AbstractAot.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/aot/AbstractAot.java index d2dda58575..0a86342b76 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/aot/AbstractAot.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/aot/AbstractAot.java @@ -92,7 +92,7 @@ public abstract class AbstractAot extends JavaExec { @IgnoreEmptyDirectories @PathSensitive(PathSensitivity.RELATIVE) public final FileCollection getInputClasses() { - return this.inputClasses.getAsFileTree().matching((filter) -> filter.include((spec) -> !spec.isDirectory())); + return this.inputClasses.getAsFileTree(); } public void setInputClasses(FileCollection inputClasses) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootAotPluginIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootAotPluginIntegrationTests.java index 1bf77abc19..00aa32533d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootAotPluginIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootAotPluginIntegrationTests.java @@ -101,10 +101,35 @@ class SpringBootAotPluginIntegrationTests { .isEqualTo(TaskOutcome.NO_SOURCE); } + @TestTemplate + void processAotRunsWhenProjectHasMainSource() throws IOException { + writeMainClass("org.springframework.boot", "AotProcessor"); + writeMainClass("com.example", "Main"); + assertThat(this.gradleBuild.build("processAot").task(":processAot").getOutcome()) + .isEqualTo(TaskOutcome.SUCCESS); + } + @TestTemplate void processTestAotIsSkippedWhenProjectHasNoTestSource() { assertThat(this.gradleBuild.build("processTestAot").task(":processTestAot").getOutcome()) .isEqualTo(TaskOutcome.NO_SOURCE); } + private void writeMainClass(String packageName, String className) throws IOException { + File java = new File(this.gradleBuild.getProjectDir(), + "src/main/java/" + packageName.replace(".", "/") + "/" + className + ".java"); + java.getParentFile().mkdirs(); + Files.writeString(java.toPath(), """ + package %s; + + public class %s { + + public static void main(String[] args) { + + } + + } + """.formatted(packageName, className)); + } + } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/SpringBootAotPluginIntegrationTests-processAotRunsWhenProjectHasMainSource.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/SpringBootAotPluginIntegrationTests-processAotRunsWhenProjectHasMainSource.gradle new file mode 100644 index 0000000000..b77b1da056 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/SpringBootAotPluginIntegrationTests-processAotRunsWhenProjectHasMainSource.gradle @@ -0,0 +1,13 @@ +plugins { + id 'org.springframework.boot' + id 'org.springframework.boot.aot' + id 'java' +} + +repositories { + mavenCentral() +} + +springBoot { + mainClass = 'com.example.Main' +}