shadow icon indicating copy to clipboard operation
shadow copied to clipboard

can not choose a file over another using mergeServiceFiles()

Open chris-brace opened this issue 3 years ago • 2 comments

Sometimes with log4j2 you need to override the file META-INF/services/org.apache.logging.log4j.core.util.ContextDataProvider to specify your own ContextDataProvider ( https://logging.apache.org/log4j/2.x/manual/extending.html#ContextDataProvider ). There does not seem to be a way to specify this in any other way but the meta-inf services file. However, if i do not intervene, shadowJar seems to "choose" the one provided by the log4j2 library, even though i provide my own in my resources/META-INF/services dir. When i do

tasks.withType<ShadowJar> {
    manifest {
        attributes(mapOf("Multi-Release" to "true"))
    }
    mergeServiceFiles {
        include("META-INF/services/io.vertx.core.spi.VerticleFactory")
        include("META-INF/services/org.apache.logging.log4j.core.util.ContextDataProvider")
    }
}

the jar contains the correct file but it has BOTH lines in it (the one from log4j2-core, and the one from the file i created in my own src tree). I really just want to override it with my own but i am not sure how.

chris-brace avatar Sep 28 '21 17:09 chris-brace

I have also confirmed that this works with the normal run gradle task: it includes my file instead of the one provided by log4j2-core.

chris-brace avatar Sep 28 '21 17:09 chris-brace

I'm pretty sure it works in your repo due to classpath ordering, which isn't really guaranteed. Have you tried using any exclude configurations to drop the file from log4j?

johnrengelman avatar Mar 21 '23 12:03 johnrengelman