Add a task to warm Gradle's caches
A new warmCaches task is added to each smoke test. This task downloads all of the dependencies on the classpaths of the test's main, test, and appTest source sets. It is intended for us in GitHub Actions to make more efficient use of its cache and increase the likelihood of a cache hit when running each individual set of smoke tests.
This commit is contained in:
@@ -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<Project> {
|
||||
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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user