From 2b503ee334da9c196fe7023bd1ff2b8c2ecd392f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 15 Sep 2022 14:02:54 +0100 Subject: [PATCH] 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 --- .../boot/gradle/plugin/SpringBootAotPlugin.java | 4 +--- 1 file changed, 1 insertion(+), 3 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 b8292397b9..207697a4f3 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 @@ -33,7 +33,6 @@ import org.gradle.api.provider.Provider; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetContainer; 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.ProcessAot; @@ -123,8 +122,7 @@ public class SpringBootAotPlugin implements Plugin { task.getApplicationClass() .set(resolveMainClassName.flatMap(ResolveMainClassName::readMainClassName)); }); - project.getTasks().named(aotSourceSet.getCompileJavaTaskName(), JavaCompile.class).configure( - (javaCompile) -> javaCompile.setClasspath(javaCompile.getClasspath().plus(project.files(aotClasses)))); + project.getDependencies().add(aotSourceSet.getImplementationConfigurationName(), project.files(aotClasses)); aotSourceSet.getOutput().dir(aotClasses); configureDependsOn(project, aotSourceSet, processAot); }