How to retrieve Scala's version in REPL?

Viewed 4126

When trying to run some code in online interpreters or with IRC bots, I always wonder which version of Scala they support.

Is there a way to retrieve the version of Scala from within the interpreter?

4 Answers

If you need just the version number without the "version" keyword you can use versionNumberString function.

scala> scala.util.Properties.versionNumberString
res1: String = 2.12.3

If you want to get the exact Scala 3 version, you can read it from the Manifest file
.../scala3-library_3-3.0.1.jar!/META-INF/MANIFEST.MF

import java.io.FileInputStream
import java.util.jar.JarInputStream

val scala3LibJar = classOf[CanEqual[_, _]].getProtectionDomain.getCodeSource.getLocation.toURI.getPath
val manifest = new JarInputStream(new FileInputStream(scala3LibJar)).getManifest
manifest.getMainAttributes.getValue("Implementation-Version")

Example in Scastie:

enter image description here

Related