Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicates from jars are not handled per duplicatesStrategy #1223

Closed
abdulowork opened this issue Feb 3, 2025 · 1 comment · Fixed by #1233
Closed

Duplicates from jars are not handled per duplicatesStrategy #1223

abdulowork opened this issue Feb 3, 2025 · 1 comment · Fixed by #1233
Labels

Comments

@abdulowork
Copy link

abdulowork commented Feb 3, 2025

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

@abdulowork abdulowork added the bug label Feb 3, 2025
@Goooler
Copy link
Member

Goooler commented Feb 6, 2025

Related to #488.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants