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

Unsupported class file major version 65 #911

Open str8y opened 3 months ago

str8y commented 3 months ago

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

Shadow Version

8.1.1

Gradle Version

8.3

Java Version

17

Expected Behavior

It definitely worked with the same configuration a couple of weeks ago

Actual Behavior

Seems that any of the dependencies was updated to a version built with Java 21 or why does this issue suddenly occurs?

java.lang.IllegalArgumentException: Unsupported class file major version 65 at org.objectweb.asm.ClassReader.(ClassReader.java:199) at org.objectweb.asm.ClassReader.(ClassReader.java:180) at org.objectweb.asm.ClassReader.(ClassReader.java:166) at org.objectweb.asm.ClassReader.(ClassReader.java:287) at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:484) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:72) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:277) at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.remapClass(ShadowCopyAction.groovy:339) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:578) at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:48) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:189) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:57) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:203) at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.remapClass(ShadowCopyAction.groovy:317) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:578) at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:48) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:189) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:57) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:194) at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction.visitArchiveFile(ShadowCopyAction.groovy:286) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:578) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:362) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:61) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:194) at com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction$StreamAction$_processArchive_closure3.doCall(ShadowCopyAction.groovy:263)

Goooler commented 3 months ago

Duplicate of #894

str8y commented 3 months ago

@Goooler

Are you sure it's a duplicate? As mentioned, it worked a few weeks ago with exactly the same configuration. I don't want to use Java 21 or a newer gradle version. I just want to understand what was changed, that the current config doesn't work anymore

Goooler commented 3 months ago

Your classes are built on Java 21 for now. If you want to pin the byte code level to lower, try to declare sourceCompatibility and targetCompatibility.

str8y commented 3 months ago

Again, I haven't changed anything in my gradle configuration. What do you mean with "your classes"? We only use Java 17. My classes are built on Java 17. sourceCompatibility and targetCompatibility are also set to 17. The shadow plugin just stopped working without any changes on my side and apparently no changes on the shadow plugin side. That's why I think it must be one of the used dependencies by the shadow plugin. With the libraries, that I actually shadow, I don't see a problem, because we are using them anyway in our Java 17 environment.

Goooler commented 3 months ago

Your shadowed dependencies may contain Java 21 classes, you can try out my fork to check if it works for you, see https://github.com/johnrengelman/shadow/pull/876#issuecomment-1783983216. As a workaround, you can also try https://github.com/johnrengelman/shadow/pull/876#issuecomment-1942380071.

str8y commented 3 months ago

I will give your fork a try but I still think that the issue is related to a dependency used by the shadow plugin itself. Because I even get the error when I have something like shadowJar { relocate('a', 'b') {} }

str8y commented 3 months ago

your fork is working... I still would be interested in the actual issue though... :) Thanks for the help so far