johnrengelman / shadow

Gradle plugin to create fat/uber JARs, apply file transforms, and relocate packages for applications and libraries. Gradle version of Maven's Shade plugin.
http://imperceptiblethoughts.com/shadow/
Apache License 2.0
3.59k stars 386 forks source link

Resources file in META-INF folder - conflict between shadded and not-shadded files. #905

Closed mosaikdoc closed 3 months ago

mosaikdoc commented 3 months ago

Please check the User Guide before submitting "how do I do 'x'?" questions!

Shadow Version

6.1.0

Gradle Version

7.5.1

Expected Behavior

Actual Behavior

Due to version conflict, I need to shade/relocate axiom-api and axiom-impl jars. Using com.github.johnrengelman.shadow (v6.1.0), with the following build.gradle :

plugins {
    id 'com.github.johnrengelman.shadow' version '6.1.0'
    id 'java'
}
repositories {
    flatDir { dirs 'lib'}
    ...
}
dependencies {
    implementation fileTree(dir: 'lib', include: 'axiom*.jar')
    ...
}
shadowJar {
    relocate('org.apache.axiom','test.shadow.apache.axiom')
    ...
}

the classes have been relocated correctly, but 3 problems remain:

1 - META-INF/axiom.xml (from axiom-impl) contents have not been replaced :

        <implementations xmlns="http://ws.apache.org/axiom/">
            <implementation name="llom" loader="org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactoryLoader">
                <feature name="default" priority="100"/>
            </implementation>
        </implementations>

I need to relocate him to "test.shadow.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactoryLoader".

2 - Two META-INF/axiom.xml files are in conflict (shadded and non-shadded). File is accessed in this way: Class "org.apache.axiom.locator.ImplementationFactory" (axiom-impl) offers the file :

            static final String **DESCRIPTOR_RESOURCE** = "**META-INF/axiom.xml**";

and org.apache.axiom.locator.DefaultOMMetaFactoryLocator (axiom-api) uses de file :

            classLoader.getResources(ImplementationFactory.**DESCRIPTOR_RESOURCE**);

I need to rename (META-INF/axiom-shadow.xml) or move (META-INF/shadow/axiom.xml) the shadded file, in order to avoid conflict.

3 - I need the class "org.apache.axiom.locator.ImplementationFactory" to be modified to offer the shadded file (renamed or moved).

                      static final String DESCRIPTOR_RESOURCE = "**META-INF/axiom-shadow.xml**";

Is it possible to do this with the Shadow plugin?

Many thanks.

Gradle Build Script(s)

Content of Shadow JAR (jar tf <jar file> - post link to GIST if too long)

mosaikdoc commented 3 months ago

GIST : https://gist.github.com/mosaikdoc/5c4a293ea0d6b939e3d165aff1dd8e4e

mosaikdoc commented 3 months ago

Wrong request. Replaced by 906.