Skip to content

Commit

Permalink
Merge pull request #1 from ribafish/gk/fixCacheInspectClasspath-inter…
Browse files Browse the repository at this point in the history
…nalInput

Make runtimeclasspath an internal input for InspectClasspath
  • Loading branch information
ribafish authored Jan 30, 2024
2 parents e92bdd6 + b0af544 commit 0c396a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Classpath;
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 @@ -31,17 +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();

@InputFiles
@Classpath
@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 @@ -51,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

0 comments on commit 0c396a4

Please sign in to comment.