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. #906

Open mosaikdoc opened 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','eu.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 his loader to "eu.shadow.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactoryLoader".

2 - Two META-INF/axiom.xml files are in conflict (shadded and non-shadded). This files offers a resource with the same qualified name (see below). I need to "relocate" xmlns to "http://ws.apache.shadow.eu/axiom/" for conflict avoiding.

3 - For resource use, class "org.apache.axiom.locator.ImplementationFactory" (axiom-impl) defines : private static final String NS = "http://ws.apache.org/axiom/"; I need that shadded "eu.shadow.apache.axiom.locator.ImplementationFactory" "relocates" this value to : private static final String NS = "http://ws.apache.shadow.eu/axiom/ in order to reach the desired relocated resource.

Is it possible to do this with the Shadow plugin?

Many thanks.

NOTE : I made all these modifications by hand, with text and hexa editors, directly on the output shadow jar, and it works. I modified axiom.xml and ImplementationFactory.class files.

Gradle Build Script(s)

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

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