Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed cache misses caused by inspectRuntimeClasspath tasks. #918

Merged
merged 6 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
Expand All @@ -30,22 +32,22 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;
import java.util.stream.Collectors;

@CacheableTask
public abstract class ApplicationClasspathInspector extends DefaultTask {
@InputFiles
@PathSensitive(PathSensitivity.RELATIVE)
public abstract ConfigurableFileCollection getResources();

/**
* The runtime classpath. Curently we only care about the file names,
* which is why the path sensitivity is set to name only.
* @return the runtime classpath
*/
@InputFiles
@PathSensitive(PathSensitivity.NAME_ONLY)
@Internal
public abstract ConfigurableFileCollection getRuntimeClasspath();

@Input
public Set<String> getResolvedClasspathNames() {
return getRuntimeClasspath().getFiles().stream().map(File::getName).collect(Collectors.toSet());
}

@OutputFile
public abstract RegularFileProperty getReportFile();

Expand All @@ -55,8 +57,7 @@ void inspect() throws IOException {
Set<File> resources = getResources().getFiles();
if (resources.stream().anyMatch(ApplicationClasspathInspector::isYamlConfigurationFile)) {
writer.println("YAML configuration file detected");
Set<File> runtimeClasspath = getRuntimeClasspath().getFiles();
if (runtimeClasspath.stream().noneMatch(f -> f.getName().startsWith("snakeyaml"))) {
if (getResolvedClasspathNames().stream().noneMatch(n -> n.startsWith("snakeyaml"))) {
writer.println("Didn't find snakeyaml on classpath. Failing");
throw new RuntimeException("YAML configuration file detected but snakeyaml is not on classpath. Make sure to add a runtimeOnly dependency on snakeyaml, e.g 'runtimeOnly(\"org.yaml:snakeyaml\")'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ private void configureDefaultGroovySourceSet(Project p,

private static TaskProvider<ApplicationClasspathInspector> registerInspectRuntimeClasspath(Project project, TaskContainer tasks) {
return tasks.register(INSPECT_RUNTIME_CLASSPATH_TASK_NAME, ApplicationClasspathInspector.class, task -> {
var javaPluginExtension = PluginsHelper.javaPluginExtensionOf(project);
task.setGroup(BasePlugin.BUILD_GROUP);
task.setDescription("Performs sanity checks of the runtime classpath to warn about misconfigured builds");
task.getRuntimeClasspath().from(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
Expand Down
Loading