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 2aa21e2d7c..07b7b813d9 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 @@ -86,7 +86,8 @@ public class SpringBootAotPlugin implements Plugin { return sourceSets.create(newSourceSetName, (sourceSet) -> { sourceSet.getJava().setSrcDirs(List.of("build/generated/" + newSourceSetName + "Sources")); sourceSet.getResources().setSrcDirs(List.of("build/generated/" + newSourceSetName + "Resources")); - sourceSet.setCompileClasspath(sourceSet.getCompileClasspath().plus(existingSourceSet.getOutput())); + sourceSet.setCompileClasspath(sourceSet.getCompileClasspath().plus(existingSourceSet.getCompileClasspath()) + .plus(existingSourceSet.getOutput())); existingSourceSet.setRuntimeClasspath(existingSourceSet.getRuntimeClasspath().plus(sourceSet.getOutput())); ConfigurationContainer configurations = project.getConfigurations(); Configuration implementation = configurations.getByName(sourceSet.getImplementationConfigurationName()); @@ -151,7 +152,7 @@ public class SpringBootAotPlugin implements Plugin { ProcessTestAot.class, (task) -> { configureAotTask(project, aotTestSourceSet, task, project.getLayout().getBuildDirectory().dir("generated/aotTestClasses")); - task.setTestClassesDirs(testSourceSet.getOutput().getClassesDirs()); + task.setTestSourceSet(testSourceSet); }); configureDependsOn(project, aotTestSourceSet, processTestAot); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/aot/ProcessTestAot.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/aot/ProcessTestAot.java index 8e62d0631d..df0700c428 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/aot/ProcessTestAot.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/aot/ProcessTestAot.java @@ -29,6 +29,7 @@ import org.gradle.api.file.FileCollection; import org.gradle.api.tasks.CacheableTask; import org.gradle.api.tasks.Classpath; import org.gradle.api.tasks.JavaExec; +import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskAction; import org.springframework.boot.gradle.plugin.SpringBootPlugin; @@ -42,7 +43,7 @@ import org.springframework.boot.gradle.plugin.SpringBootPlugin; @CacheableTask public class ProcessTestAot extends AbstractAot { - private final FileCollection junitPlatformLauncher; + private final Configuration junitPlatformLauncher; private FileCollection testClassesDirs; @@ -84,7 +85,14 @@ public class ProcessTestAot extends AbstractAot { .collect(Collectors.joining(File.pathSeparator))); args.addAll(processorArgs()); this.setArgs(args); + this.classpath(this.junitPlatformLauncher); super.exec(); } + public void setTestSourceSet(SourceSet testSourceSet) { + setTestClassesDirs(testSourceSet.getOutput().getClassesDirs()); + this.junitPlatformLauncher.extendsFrom( + getProject().getConfigurations().getByName(testSourceSet.getImplementationConfigurationName())); + } + }