Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnsupportedClassVersionError since sbt-scalafmt 2.5.3 #344

Closed
xuwei-k opened this issue Jan 13, 2025 · 9 comments · Fixed by #345 or #346
Closed

UnsupportedClassVersionError since sbt-scalafmt 2.5.3 #344

xuwei-k opened this issue Jan 13, 2025 · 9 comments · Fixed by #345 or #346

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented Jan 13, 2025

Configuration (required)

use JDK 8

.scalafmt.conf

version = "3.8.3"
runner.dialect = Scala3

project/build.properties

sbt.version=1.10.7

project/plugins.sbt

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.3")

Command-line parameters (required)

sbt scalafmt

Problem (required)

java.lang.UnsupportedClassVersionError: org/scalafmt/interfaces/Scalafmt has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at org.scalafmt.sbt.ScalafmtPlugin$.<init>(ScalafmtPlugin.scala:108)
	at org.scalafmt.sbt.ScalafmtPlugin$.<clinit>(ScalafmtPlugin.scala)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at sbt.internal.inc.ModuleUtilities$.getObject(ModuleUtilities.scala:24)
	at sbt.internal.inc.ModuleUtilities$.getCheckedObject(ModuleUtilities.scala:32)
	at sbt.internal.inc.ModuleUtilities$.$anonfun$getCheckedObjects$1(ModuleUtilities.scala:37)
	at scala.collection.immutable.Stream.map(Stream.scala:418)
	at sbt.internal.inc.ModuleUtilities$.getCheckedObjects(ModuleUtilities.scala:37)
	at sbt.internal.PluginDiscovery$.loadModules(PluginDiscovery.scala:164)

Expectation

Workaround

Notes

This was referenced Jan 13, 2025
@kitbellew
Copy link
Contributor

@tgodzik @xuwei-k @ckipp01 do you know how to solve this?

@kitbellew
Copy link
Contributor

ok, chatgpt says 52.0 is for java 8, and 55.0 for java 11; it is true we no longer release for java 8. i thought java 8 was deprecated a while ago.

also, one of the contributors added a section mentioning that java 8 support was dropped in 2.5.1.

but in mima it used 2.5.2 successfully...

@gaeljw
Copy link

gaeljw commented Jan 14, 2025

Facing the same error in cucumber/cucumber-jvm-scala#384, Java 8 support got dropped in 2.5.3 (was working in 2.5.2).

IMHO it should have been done in a minor version, not a bugfix one, with an explicit mention in the release notes even though we all agree that JDK8 should go away :)

@tgodzik
Copy link
Contributor

tgodzik commented Jan 14, 2025

@tgodzik @xuwei-k @ckipp01 do you know how to solve this?

We can separate release into website and normal release, which we can run on JDK 8 or just add -release 8 flag to scalacOptions. Both should work since mdoc documentation is not published. I can do that, just let me know.

We can drop the version explicitly later on.

@xuwei-k
Copy link
Contributor Author

xuwei-k commented Jan 14, 2025

just add -release 8 flag to scalacOption

org/scalafmt/interfaces/Scalafmt is java code. not scalacOptions. add javacOptions

https://github.com/scalameta/scalafmt/blob/v3.8.4/scalafmt-interfaces/jvm/src/main/java/org/scalafmt/interfaces/Scalafmt.java

@tgodzik
Copy link
Contributor

tgodzik commented Jan 14, 2025

just add -release 8 flag to scalacOption

org/scalafmt/interfaces/Scalafmt is java code. not scalacOptions. add javacOptions

https://github.com/scalameta/scalafmt/blob/v3.8.4/scalafmt-interfaces/jvm/src/main/java/org/scalafmt/interfaces/Scalafmt.java

Ach, yes, sorry. We should most likely add both just in case

@kitbellew
Copy link
Contributor

@tgodzik @xuwei-k @ckipp01 do you know how to solve this?

We can separate release into website and normal release, which we can run on JDK 8 or just add -release 8 flag to scalacOptions. Both should work since mdoc documentation is not published. I can do that, just let me know.

I tried adding scalacOptions ++= Seq("-release", "8") to -dynamic and -sysops, and also javacOptions ++= Seq("--release", "8") to -interfaces; then used javap -v on the resulting class files and saw 52 on the dynamic classes but 65 on the interfaces classes.

Whatever I did, I could't get java files to become 52. Since I don't know much about this, I used chatgpt and gemini to guide me, and they hallucinated a little bit but perhaps too much.

anyway, @tgodzik, if you understand how to do this, could you please help?

@tgodzik
Copy link
Contributor

tgodzik commented Jan 15, 2025

scalameta/scalafmt#4719

@xuwei-k
Copy link
Contributor Author

xuwei-k commented Jan 16, 2025

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants