Skip to content

Commit 6175c42

Browse files
committed
Fix skipping of processAot when there is no main source
See gh-32424
1 parent 67cc991 commit 6175c42

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/aot/AbstractAot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public final DirectoryProperty getClassesOutput() {
9292
@IgnoreEmptyDirectories
9393
@PathSensitive(PathSensitivity.RELATIVE)
9494
public final FileCollection getInputClasses() {
95-
return this.inputClasses.getAsFileTree().matching((filter) -> filter.include((spec) -> !spec.isDirectory()));
95+
return this.inputClasses.getAsFileTree();
9696
}
9797

9898
public void setInputClasses(FileCollection inputClasses) {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootAotPluginIntegrationTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,35 @@ void processAotIsSkippedWhenProjectHasNoMainSource() {
101101
.isEqualTo(TaskOutcome.NO_SOURCE);
102102
}
103103

104+
@TestTemplate
105+
void processAotRunsWhenProjectHasMainSource() throws IOException {
106+
writeMainClass("org.springframework.boot", "AotProcessor");
107+
writeMainClass("com.example", "Main");
108+
assertThat(this.gradleBuild.build("processAot").task(":processAot").getOutcome())
109+
.isEqualTo(TaskOutcome.SUCCESS);
110+
}
111+
104112
@TestTemplate
105113
void processTestAotIsSkippedWhenProjectHasNoTestSource() {
106114
assertThat(this.gradleBuild.build("processTestAot").task(":processTestAot").getOutcome())
107115
.isEqualTo(TaskOutcome.NO_SOURCE);
108116
}
109117

118+
private void writeMainClass(String packageName, String className) throws IOException {
119+
File java = new File(this.gradleBuild.getProjectDir(),
120+
"src/main/java/" + packageName.replace(".", "/") + "/" + className + ".java");
121+
java.getParentFile().mkdirs();
122+
Files.writeString(java.toPath(), """
123+
package %s;
124+
125+
public class %s {
126+
127+
public static void main(String[] args) {
128+
129+
}
130+
131+
}
132+
""".formatted(packageName, className));
133+
}
134+
110135
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id 'org.springframework.boot'
3+
id 'org.springframework.boot.aot'
4+
id 'java'
5+
}
6+
7+
repositories {
8+
mavenCentral()
9+
}
10+
11+
springBoot {
12+
mainClass = 'com.example.Main'
13+
}

0 commit comments

Comments
 (0)