shadow icon indicating copy to clipboard operation
shadow copied to clipboard

Using the Log4j2PluginsCacheFileTransformer leads to multiple Log4j2Plugins.dat files

Open Ultranium opened this issue 4 years ago • 3 comments

I use the logstash-gelf log4j plugin in my project. I also have another @Plugin-annotated class in my project for log4j2 configuration.

If I use the Log4j2PluginsCacheFileTransformer to combine log4j plugin cache files, I end up with two Log4j2Plugins.dat files in the META-INF/org/apache/logging/log4j/core/config/plugins/ directory of my fat JAR (I didn't even know it is possible lol) and log4j2 fails to load my custom plugin at runtime.

A simple reproducer: https://github.com/Ultranium/shadowjar-log4j-transform-reproducer

Shadow Version

6.1.0

Gradle Version

6.8.2

Expected Behavior

Correct Log4j2Plugins.dat files merger into a single one

Actual Behavior

Multiple Log4j2Plugins.dat files the META-INF/org/apache/logging/log4j/core/config/plugins/ directory of the fat JAR

image

Gradle Build Script(s)

build.gradle
import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer

plugins {
    id 'com.github.johnrengelman.shadow' version '6.1.0'
    id 'java'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.apache.logging.log4j:log4j-api:2.14.0'
    implementation 'org.apache.logging.log4j:log4j-core:2.14.0'
    implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.0'
    annotationProcessor 'org.apache.logging.log4j:log4j-core:2.14.0'

    // logstash-gelf log4j2 plugin
    implementation 'biz.paluch.logging:logstash-gelf:1.14.1'
}

shadowJar {
    manifest {
        attributes 'Main-Class': 'com.example.App'
    }

    transform(Log4j2PluginsCacheFileTransformer)
}

Content of Shadow JAR

https://gist.github.com/Ultranium/39afc8656c5fceef8974352caaf2018e

Ultranium avatar Feb 18 '21 13:02 Ultranium