Add AOT-generated classes as a dependency

Previously, the AOT-generated classes were added directly to the
compile classpath of the AOT compilation task. This didn't work
perfectly in IntelliJ IDEA, leaving the generated classes in the
runtime scope and causing compilation problems where the
AOT-generated source tried to reference those classes.

This commit updates the plugin to add the AOT-generated classes as
a dependency to the AOT source set's implementation configuration.
This makes the classes available during compilation by the source
set's Java compilation task while also makeing IntelliJ IDEA aware
of their presence on the compile classpath.

Closes gh-32395
pull/32405/head
Andy Wilkinson 2 years ago
parent 0476b5da5d
commit 2b503ee334

@ -33,7 +33,6 @@ import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider; import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.compile.JavaCompile;
import org.springframework.boot.gradle.tasks.aot.AbstractAot; import org.springframework.boot.gradle.tasks.aot.AbstractAot;
import org.springframework.boot.gradle.tasks.aot.ProcessAot; import org.springframework.boot.gradle.tasks.aot.ProcessAot;
@ -123,8 +122,7 @@ public class SpringBootAotPlugin implements Plugin<Project> {
task.getApplicationClass() task.getApplicationClass()
.set(resolveMainClassName.flatMap(ResolveMainClassName::readMainClassName)); .set(resolveMainClassName.flatMap(ResolveMainClassName::readMainClassName));
}); });
project.getTasks().named(aotSourceSet.getCompileJavaTaskName(), JavaCompile.class).configure( project.getDependencies().add(aotSourceSet.getImplementationConfigurationName(), project.files(aotClasses));
(javaCompile) -> javaCompile.setClasspath(javaCompile.getClasspath().plus(project.files(aotClasses))));
aotSourceSet.getOutput().dir(aotClasses); aotSourceSet.getOutput().dir(aotClasses);
configureDependsOn(project, aotSourceSet, processAot); configureDependsOn(project, aotSourceSet, processAot);
} }

Loading…
Cancel
Save