Fix skipping of processAot when there is no main source

See gh-32424
pull/32205/head
Andy Wilkinson 2 years ago
parent 67cc99111c
commit 6175c4210d

@ -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) {

@ -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));
}
}

@ -0,0 +1,13 @@
plugins {
id 'org.springframework.boot'
id 'org.springframework.boot.aot'
id 'java'
}
repositories {
mavenCentral()
}
springBoot {
mainClass = 'com.example.Main'
}
Loading…
Cancel
Save