Skip to content

mergeServiceFiles() does not work as expected when using DuplicatesStrategy.EXCLUDE #1348

@ketan

Description

@ketan

Expected and Results

Here's a snippet of code that had some unexpected results:

plugins {
    id 'java-library'
    id("com.gradleup.shadow") version("9.0.0-beta10")
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("io.grpc:grpc-netty-shaded:1.63.0")
    implementation("io.grpc:grpc-core:1.63.0")

}

shadowJar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    mergeServiceFiles()
}

I was expecting that this would remove any duplicate files introduced between the 2 libs that I'm shadowing, but merge the service files.

Apparently, service files don't "merge" because duplicates are being excluded. Removing the DuplicatesStrategy.EXCLUDE seems to properly merge the service files.

In the above case, look for the file META-INF/services/io.grpc.NameResolverProvider in the generated jar.

Related environent and versions

Java:

openjdk version "17.0.14" 2025-01-21
OpenJDK Runtime Environment Temurin-17.0.14+7 (build 17.0.14+7)
OpenJDK 64-Bit Server VM Temurin-17.0.14+7 (build 17.0.14+7, mixed mode, sharing)

H/W:

mac mini m4 running macOS 15.3.2

Reproduction steps

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions