diff --git a/gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/AotSmokeTestPlugin.java b/gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/AotSmokeTestPlugin.java index 8a6091e2..0c5b5c8f 100644 --- a/gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/AotSmokeTestPlugin.java +++ b/gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/AotSmokeTestPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 the original author or authors. + * Copyright 2022-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,6 +65,7 @@ import org.springframework.aot.gradle.tasks.StartApplication; import org.springframework.aot.gradle.tasks.StartJvmApplication; import org.springframework.aot.gradle.tasks.StartNativeApplication; import org.springframework.aot.gradle.tasks.StopApplication; +import org.springframework.aot.gradle.tasks.WarmCaches; import org.springframework.boot.gradle.plugin.SpringBootPlugin; import org.springframework.boot.gradle.tasks.bundling.BootJar; @@ -181,6 +182,20 @@ public class AotSmokeTestPlugin implements Plugin { DependencyHandler dependencies = project.getRootProject().getDependencies(); dependencies.add(smokeTests.getName(), dependencies.project(Map.of("path", project.getPath(), "configuration", smokeTests.getName()))); + project.getTasks().register("warmCaches", WarmCaches.class, (warmCaches) -> { + sourceSets + .matching((sourceSet) -> List + .of(SourceSet.MAIN_SOURCE_SET_NAME, SourceSet.TEST_SOURCE_SET_NAME, APP_TEST_SOURCE_SET_NAME) + .contains(sourceSet.getName())) + .all((sourceSet) -> { + warmCaches.addDependencies( + project.getConfigurations().getByName(sourceSet.getAnnotationProcessorConfigurationName())); + warmCaches.addDependencies( + project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName())); + warmCaches.addDependencies( + project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName())); + }); + }); } private void enableJavaCompileLinting(Project project, SourceSetContainer sourceSets) { diff --git a/gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/tasks/WarmCaches.java b/gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/tasks/WarmCaches.java new file mode 100644 index 00000000..b7849ff0 --- /dev/null +++ b/gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/tasks/WarmCaches.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.aot.gradle.tasks; + +import org.gradle.api.DefaultTask; +import org.gradle.api.file.ConfigurableFileCollection; +import org.gradle.api.file.FileCollection; +import org.gradle.api.tasks.Classpath; +import org.gradle.api.tasks.TaskAction; + +/** + * Task to warm Gradle's caches by downloading the configured dependencies. + * + * @author Andy Wilkinson + */ +public class WarmCaches extends DefaultTask { + + private final ConfigurableFileCollection dependencies; + + public WarmCaches() { + this.dependencies = getProject().getObjects().fileCollection(); + } + + public void addDependencies(FileCollection dependencies) { + this.dependencies.from(dependencies); + } + + @TaskAction + void execute() { + this.dependencies.getFiles(); + } + + @Classpath + FileCollection getDependencies() { + return this.dependencies; + } + +}