-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a task that reports the artifact identifiers of the project's run…
…time classpath.
- Loading branch information
1 parent
b079ec3
commit b9aa310
Showing
5 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Long>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
org.gradle.unsafe.configuration-cache=true | ||
org.gradle.unsafe.configuration-cache=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ComponentArtifactIdentifier> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Project> { | ||
@Override | ||
public void apply(Project target) { | ||
target.getPlugins().apply("java-library"); | ||
|
||
target.getTasks().register("artifacts-report", ReportArtifactMetadataTask.class, t -> { | ||
Provider<Set<ResolvedArtifactResult>> 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")); | ||
}); | ||
} | ||
} |