Skip to content

Commit 60c4f68

Browse files
bric3sarahchen6
andauthored
Tweak shadowJar/archive configurations (#9732)
* chore: Tweak shadowJar/archive configurations * fix: Properly configure artifacts in a lazy way * chore: Simplify archives configurations as we don't need the zip or tar distributions * chore: Allow the artifacts task to receive command line options * chore: PR suggestions Co-authored-by: Sarah Chen <[email protected]> --------- Co-authored-by: Sarah Chen <[email protected]>
1 parent aa59053 commit 60c4f68

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

gradle/java_no_deps.gradle

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,20 +299,21 @@ tasks.withType(JavaExec).configureEach {
299299
}
300300
}
301301

302-
if (project.plugins.hasPlugin('com.gradleup.shadow')) {
302+
// For reproducible builds
303+
tasks.withType(AbstractArchiveTask).configureEach {
304+
preserveFileTimestamps = false
305+
reproducibleFileOrder = true
306+
}
307+
308+
project.pluginManager.withPlugin('com.gradleup.shadow') {
303309
// Remove the no-deps jar from the archives to prevent publication
304-
configurations.archives.with {
305-
artifacts.remove artifacts.find {
306-
if (it.hasProperty("delegate")) {
307-
it.delegate.archiveTask.is jar
308-
} else {
309-
it.archiveTask.is jar
310-
}
310+
// Also removes other distribution types (zip, tar etc.), only affects project in dd-smoke-tests
311+
configurations {
312+
named("archives") {
313+
outgoing.artifacts.clear()
314+
outgoing.artifact(project.tasks.named("shadowJar"))
311315
}
312316
}
313-
artifacts {
314-
archives(shadowJar)
315-
}
316317
}
317318

318319
if (project.hasProperty("removeJarVersionNumbers") && project.findProperty("removeJarVersionNumbers").asBoolean()) {

gradle/util.gradle

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
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() {
516
// 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())
1029
}
11-
println ' '
1230
}
1331
}
1432
}
1533

34+
tasks.register("artifacts", DisplayArtifactsTask)
35+
1636
/** Find a random, reusable port. */
1737
ext.randomOpenPort = {
1838
->

0 commit comments

Comments
 (0)