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
This commit is contained in:
Andy Wilkinson
2022-10-11 19:58:03 +01:00
parent 808e0be552
commit 3ca5c7ff5b

View File

@@ -70,14 +70,14 @@ public class SpringBootAotPlugin implements Plugin<Project> {
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);
});
});