|
1 | | -tasks.register("artifacts") { |
2 | | - group = "Help" |
3 | | - description = "Displays the artifacts associated with each configuration of " + project |
4 | | - doFirst { |
| 1 | +abstract class DisplayArtifactsTask extends DefaultTask { |
| 2 | + |
| 3 | + @Option(option = "configuration", description = "Comma separated list of configuration name (defaults to 'archives,javadocElements,sourcesElements'). Use 'all' to display all configurations.") |
| 4 | + @Input |
| 5 | + @Optional |
| 6 | + abstract Property<String> getConfigurationName() |
| 7 | + |
| 8 | + DisplayArtifactsTask() { |
| 9 | + group = "Help" |
| 10 | + description = "Displays the artifacts associated with each configuration of " + project |
| 11 | + configurationName.convention("archives,javadocElements,sourcesElements") |
| 12 | + } |
| 13 | + |
| 14 | + @TaskAction |
| 15 | + void displayArtifacts() { |
5 | 16 | // This eager access is ok as it is during the task execution phase |
6 | | - configurations.each { config -> |
7 | | - println "${config}:" |
8 | | - config.allArtifacts.getFiles().each { file -> |
9 | | - println " " + file |
| 17 | + def builder = new StringBuilder() |
| 18 | + def targetConfig = configurationName.map { it.split(",").toList().toSet() }.orNull |
| 19 | + def configs = targetConfig.contains("all") ? project.configurations : project.configurations.matching { targetConfig.contains(it.name) } |
| 20 | + configs.each { config -> |
| 21 | + def outgoingFiles = config.outgoing.artifacts.getFiles() |
| 22 | + if (!outgoingFiles.isEmpty()) { |
| 23 | + builder.setLength(0) |
| 24 | + outgoingFiles.each { file -> |
| 25 | + def relPath = project.rootDir.toPath().relativize(file.toPath()) |
| 26 | + builder.append(config).append(": ").append(relPath) |
| 27 | + } |
| 28 | + logger.quiet(builder.toString()) |
10 | 29 | } |
11 | | - println ' ' |
12 | 30 | } |
13 | 31 | } |
14 | 32 | } |
15 | 33 |
|
| 34 | +tasks.register("artifacts", DisplayArtifactsTask) |
| 35 | + |
16 | 36 | /** Find a random, reusable port. */ |
17 | 37 | ext.randomOpenPort = { |
18 | 38 | -> |
|
0 commit comments