diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 577bcc7..526a50d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -10,4 +10,5 @@ repositories { dependencies { implementation(project(":util")) implementation("test.libs:lib1:1.0") + implementation("org.apache.commons:commons-collections4:4.4") } \ No newline at end of file diff --git a/app/src/main/java/App.java b/app/src/main/java/App.java index 5d7a2f6..48fda43 100644 --- a/app/src/main/java/App.java +++ b/app/src/main/java/App.java @@ -1,6 +1,9 @@ +import org.apache.commons.collections4.map.LinkedMap; + public class App { public static void main(String[] args) { new Util(); new Lib1(); + new LinkedMap(); } } diff --git a/gradle.properties b/gradle.properties index 5b328bf..a159719 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -org.gradle.unsafe.configuration-cache=true +org.gradle.unsafe.configuration-cache=false diff --git a/plugins/src/main/java/ReportArtifactMetadataTask.java b/plugins/src/main/java/ReportArtifactMetadataTask.java new file mode 100644 index 0000000..d711674 --- /dev/null +++ b/plugins/src/main/java/ReportArtifactMetadataTask.java @@ -0,0 +1,31 @@ +import org.gradle.api.DefaultTask; +import org.gradle.api.artifacts.component.ComponentArtifactIdentifier; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.ListProperty; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +public abstract class ReportArtifactMetadataTask extends DefaultTask { + @Input + public abstract ListProperty getArtifacts(); + + @OutputFile + public abstract RegularFileProperty getOutputFile(); + + @TaskAction + public void report() throws IOException { + File outputFile = getOutputFile().getAsFile().get(); + try (PrintWriter writer = new PrintWriter(new FileWriter(outputFile))) { + for (ComponentArtifactIdentifier id : getArtifacts().get()) { + writer.println(id.getDisplayName()); + } + } + System.out.println("Wrote report to " + outputFile); + } +} diff --git a/plugins/src/main/java/TestPlugin.java b/plugins/src/main/java/TestPlugin.java index a1a13d1..7b0b9b2 100644 --- a/plugins/src/main/java/TestPlugin.java +++ b/plugins/src/main/java/TestPlugin.java @@ -1,9 +1,21 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.artifacts.result.ArtifactResult; +import org.gradle.api.artifacts.result.ResolvedArtifactResult; +import org.gradle.api.provider.Provider; + +import java.util.Set; +import java.util.stream.Collectors; public class TestPlugin implements Plugin { @Override public void apply(Project target) { target.getPlugins().apply("java-library"); + + target.getTasks().register("artifacts-report", ReportArtifactMetadataTask.class, t -> { + Provider> artifacts = target.getConfigurations().getByName("runtimeClasspath").getIncoming().getArtifacts().getResolvedArtifacts(); + t.getArtifacts().set(artifacts.map(s -> s.stream().map(ArtifactResult::getId).collect(Collectors.toList()))); + t.getOutputFile().set(target.getLayout().getBuildDirectory().file("artifacts.txt")); + }); } }