|
|
|
@ -71,18 +71,21 @@ public class SpringBootAotPlugin implements Plugin<Project> {
|
|
|
|
|
PluginContainer plugins = project.getPlugins();
|
|
|
|
|
plugins.withType(JavaPlugin.class).all((javaPlugin) -> {
|
|
|
|
|
plugins.withType(SpringBootPlugin.class).all((bootPlugin) -> {
|
|
|
|
|
SourceSet aotSourceSet = configureSourceSet(project, "aot", SourceSet.MAIN_SOURCE_SET_NAME);
|
|
|
|
|
registerProcessAotTask(project, aotSourceSet);
|
|
|
|
|
SourceSet aotTestSourceSet = configureSourceSet(project, "aotTest", SourceSet.TEST_SOURCE_SET_NAME);
|
|
|
|
|
registerProcessTestAotTask(project, aotTestSourceSet);
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SourceSet configureSourceSet(Project project, String newSourceSetName, String existingSourceSetName) {
|
|
|
|
|
private SourceSet configureSourceSet(Project project, String newSourceSetName, SourceSet existingSourceSet) {
|
|
|
|
|
JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
|
|
|
|
|
SourceSetContainer sourceSets = javaPluginExtension.getSourceSets();
|
|
|
|
|
SourceSet existingSourceSet = sourceSets.getByName(existingSourceSetName);
|
|
|
|
|
return sourceSets.create(newSourceSetName, (sourceSet) -> {
|
|
|
|
|
sourceSet.getJava().setSrcDirs(List.of("build/generated/" + newSourceSetName + "Sources"));
|
|
|
|
|
sourceSet.getResources().setSrcDirs(List.of("build/generated/" + newSourceSetName + "Resources"));
|
|
|
|
@ -112,13 +115,13 @@ public class SpringBootAotPlugin implements Plugin<Project> {
|
|
|
|
|
attributes.attribute(Usage.USAGE_ATTRIBUTE, javaRuntime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void registerProcessAotTask(Project project, SourceSet aotSourceSet) {
|
|
|
|
|
private void registerProcessAotTask(Project project, SourceSet aotSourceSet, SourceSet mainSourceSet) {
|
|
|
|
|
TaskProvider<ResolveMainClassName> resolveMainClassName = project.getTasks()
|
|
|
|
|
.named(SpringBootPlugin.RESOLVE_MAIN_CLASS_NAME_TASK_NAME, ResolveMainClassName.class);
|
|
|
|
|
Provider<Directory> aotClasses = project.getLayout().getBuildDirectory().dir("generated/aotClasses");
|
|
|
|
|
TaskProvider<ProcessAot> processAot = project.getTasks().register(PROCESS_AOT_TASK_NAME, ProcessAot.class,
|
|
|
|
|
(task) -> {
|
|
|
|
|
configureAotTask(project, aotSourceSet, task, aotClasses);
|
|
|
|
|
configureAotTask(project, aotSourceSet, task, aotClasses, mainSourceSet);
|
|
|
|
|
task.getApplicationClass()
|
|
|
|
|
.set(resolveMainClassName.flatMap(ResolveMainClassName::readMainClassName));
|
|
|
|
|
});
|
|
|
|
@ -128,13 +131,14 @@ public class SpringBootAotPlugin implements Plugin<Project> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void configureAotTask(Project project, SourceSet sourceSet, AbstractAot task,
|
|
|
|
|
Provider<Directory> generatedClasses) {
|
|
|
|
|
Provider<Directory> generatedClasses, SourceSet inputSourceSet) {
|
|
|
|
|
task.setClasspath(sourceSet.getCompileClasspath());
|
|
|
|
|
task.getSourcesDir().set(sourceSet.getJava().getSrcDirs().iterator().next());
|
|
|
|
|
task.getResourcesDir().set(sourceSet.getResources().getSrcDirs().iterator().next());
|
|
|
|
|
task.getClassesDir().set(generatedClasses);
|
|
|
|
|
task.getSourcesOutput().set(sourceSet.getJava().getSrcDirs().iterator().next());
|
|
|
|
|
task.getResourcesOutput().set(sourceSet.getResources().getSrcDirs().iterator().next());
|
|
|
|
|
task.getClassesOutput().set(generatedClasses);
|
|
|
|
|
task.getGroupId().set(project.provider(() -> String.valueOf(project.getGroup())));
|
|
|
|
|
task.getArtifactId().set(project.provider(() -> project.getName()));
|
|
|
|
|
task.setInputClasses(inputSourceSet.getOutput().getClassesDirs());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void configureDependsOn(Project project, SourceSet aotSourceSet,
|
|
|
|
@ -145,15 +149,13 @@ public class SpringBootAotPlugin implements Plugin<Project> {
|
|
|
|
|
.configure((processResources) -> processResources.dependsOn(processAot));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void registerProcessTestAotTask(Project project, SourceSet aotTestSourceSet) {
|
|
|
|
|
JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
|
|
|
|
|
SourceSetContainer sourceSets = javaPluginExtension.getSourceSets();
|
|
|
|
|
SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
|
|
|
|
|
private void registerProcessTestAotTask(Project project, SourceSet aotTestSourceSet, SourceSet testSourceSet) {
|
|
|
|
|
Provider<Directory> aotTestClasses = project.getLayout().getBuildDirectory().dir("generated/aotTestClasses");
|
|
|
|
|
TaskProvider<ProcessTestAot> processTestAot = project.getTasks().register(PROCESS_TEST_AOT_TASK_NAME,
|
|
|
|
|
ProcessTestAot.class, (task) -> {
|
|
|
|
|
configureAotTask(project, aotTestSourceSet, task, aotTestClasses);
|
|
|
|
|
task.setTestSourceSet(testSourceSet);
|
|
|
|
|
configureAotTask(project, aotTestSourceSet, task, aotTestClasses, testSourceSet);
|
|
|
|
|
task.setTestRuntimeClasspath(
|
|
|
|
|
project.getConfigurations().getByName(testSourceSet.getImplementationConfigurationName()));
|
|
|
|
|
});
|
|
|
|
|
project.getDependencies().add(aotTestSourceSet.getImplementationConfigurationName(),
|
|
|
|
|
project.files(aotTestClasses));
|
|
|
|
|