-
-
Notifications
You must be signed in to change notification settings - Fork 423
Duplicates from jars are not handled per duplicatesStrategy #1223
Copy link
Copy link
Closed
Labels
Description
Expected and Results
ShadowJar task supports re-embedding of contents of other jars using the shadowTask.from(jarToEmbed) API. However, duplicates encountered across the jars always get excluded, regardless of the duplicatesStrategy configuration. The only duplicates the ShadowJar recognizes are the duplicates among the copied files.
The expected behavior is that ShadowJar treats duplicates per duplicationStrategy regardless of whether they come from.
Related environent and versions
No response
Reproduction steps
Consider the following ShadowJar task configuration:
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.util.zip.ZipInputStream
plugins {
id("com.github.johnrengelman.shadow") version "8.1.1"
}
fun makeFoo(value: String): TaskProvider<*> = tasks.register(value) {
val out = layout.buildDirectory.file("${value}/foo")
outputs.file(out)
doLast {
out.get().asFile.writeText(value)
}
}
val foo1 = makeFoo("1")
val jar1 = tasks.register<Jar>("jar1") {
from(foo1)
archiveBaseName.set("jar1")
destinationDirectory.set(layout.buildDirectory.dir("jar1"))
}
val foo2 = makeFoo("2")
val jar2 = tasks.register<Jar>("jar2") {
from(foo2)
archiveBaseName.set("jar2")
destinationDirectory.set(layout.buildDirectory.dir("jar2"))
}
val foo3 = makeFoo("3")
val foo4 = makeFoo("4")
val shadow = tasks.register<ShadowJar>("shadow") {
// this does nothing in terms of duplicates across embedded jars
duplicatesStrategy = DuplicatesStrategy.FAIL
archiveBaseName.set("shadow")
from(
jar1,
jar2, // duplicate from this jar gets silently excluded
foo3, // this is also silently ignored
foo4, // but this duplicate is suddenly recognized as a duplicate
)
val output = layout.buildDirectory.dir("shadow")
destinationDirectory.set(output)
doLast {
println(
ZipInputStream(
output.get().asFile.resolve("shadow.jar").inputStream()
).use {
generateSequence { it.nextEntry }.first { it.name == "foo" }
it.readBytes().decodeToString()
}
)
}
}Duplication among foo3 and foo4 is recognized, but the duplicate file foo between jar1, jar2 and foo3 for example is silently excluded.
Anything else?
No response
Reactions are currently unavailable