jython / jython

Python for the Java Platform
https://www.jython.org
Other
1.14k stars 185 forks source link

Clash over META-INF in shaded JARs #316

Closed juniartisu closed 3 months ago

juniartisu commented 3 months ago

I think this PR https://github.com/jython/jython/pull/313 cause regression. I clone master repository so it will contains this PR and then build it and when I run it I got error below: juni@Nala dist % java -jar jython.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org.python.google.common.collect.MapMaker at org.python.core.ThreadStateMapping.(ThreadStateMapping.java:31) at org.python.core.Py.(Py.java:1789) at org.python.core.PySystemState.(PySystemState.java:80) at org.python.util.jython.main(jython.java:593) Caused by: java.lang.ClassNotFoundException: org.python.google.common.collect.MapMaker at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:827) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:1095) ... 4 more

Stewori commented 3 months ago

Missing org.python.google.common.collect.MapMaker sounds like guava shading went wrong. Interestingly, the PR did not touch Guava, but just commons-compress (and commons-io). Can it be that just a guava update is required? Maybe a class was added or relocated in guava, which is not found by the new commons-compress version. Or any other idea?

juniartisu commented 3 months ago

I have no idea. I tried to use android guava and/or guava33.0.0 none of them working. Still have same error.

juniartisu commented 3 months ago

I found the fix but I have no idea why it fixed the issue :-), you may need to figure out why but doing this below work. I update build.xml and moving the guava before common-compress works. I move guava before common-compress in build.xml see below:

            <file name="asm-util-7.1.jar" />
            <file name="guava-32.1.2-jre.jar" />
            <file name="commons-compress-1.26.0.jar"/>
            <file name="commons-io-2.15.1.jar"/>
            <file name="failureaccess-1.0.1.jar" />           
            <file name="icu4j-59_1.jar" />

        <zipfileset src="extlibs/bcprov-jdk15on-1.62.jar" excludes="META-INF/**"/>
        <rule pattern="org.bouncycastle.**" result="org.python.bouncycastle.@1"/>
        <zipfileset src="extlibs/guava-32.1.2-jre.jar"/>
        <rule pattern="com.google.**" result="org.python.google.@1"/>
        <zipfileset src="extlibs/commons-compress-1.26.0.jar"/>
        <rule pattern="org.apache.commons.compress.**" result="org.python.apache.commons.compress.@1"/>
        <zipfileset src="extlibs/commons-io-2.15.1.jar"/>
        <rule pattern="org.apache.commons.io.**" result="org.python.apache.commons.io.@1"/>
        <zipfileset src="extlibs/failureaccess-1.0.1.jar"/>
Stewori commented 3 months ago

Okay, good that you found it. That is consistent what @lifebarier pointed out in https://github.com/jython/jython/issues/310#issuecomment-1977530608 Would you submit this fix as a PR?

lifebarier commented 3 months ago

Note that moving guava up will still leave shading of other jars messed up (at least it did in experimentation yesterday, someone should double check)

juniartisu commented 3 months ago

PR317 fix is good, so I am closing this issue. Thank you.