From 3ca5c7ff5bb1e45f38ff5dd878d6a2219de1de7f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 11 Oct 2022 19:58:03 +0100 Subject: [PATCH] Create AOT source sets as soon as the Java plugin is applied Previously, the AOT source sets were not created until both the Java and Spring Boot plugins had been applied. This could create ordering problems when the Spring Boot plugin's native image plugin action tried to access the AOT source sets to configure the classpaths of the nativeCompile and nativeTest tasks. If the plugins were applied in a particular order the AOT source sets would not exist and a failure would occur. This commit updates the Spring Boot AOT plugin to create the source sets as soon as the Java plugin has been applied. This ensure that they're in place when reacting to the native image plugin being applied. Closes gh-32661 --- .../boot/gradle/plugin/SpringBootAotPlugin.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootAotPlugin.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootAotPlugin.java index 418e87bbc1..73b783fa71 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootAotPlugin.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootAotPlugin.java @@ -70,14 +70,14 @@ public class SpringBootAotPlugin implements Plugin { public void apply(Project project) { PluginContainer plugins = project.getPlugins(); plugins.withType(JavaPlugin.class).all((javaPlugin) -> { + JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class); + SourceSetContainer sourceSets = javaPluginExtension.getSourceSets(); + SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); + SourceSet aotSourceSet = configureSourceSet(project, "aot", mainSourceSet); + SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME); + SourceSet aotTestSourceSet = configureSourceSet(project, "aotTest", testSourceSet); plugins.withType(SpringBootPlugin.class).all((bootPlugin) -> { - JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class); - SourceSetContainer sourceSets = javaPluginExtension.getSourceSets(); - SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); - SourceSet aotSourceSet = configureSourceSet(project, "aot", mainSourceSet); registerProcessAotTask(project, aotSourceSet, mainSourceSet); - SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME); - SourceSet aotTestSourceSet = configureSourceSet(project, "aotTest", testSourceSet); registerProcessTestAotTask(project, aotTestSourceSet, testSourceSet); }); });