This is not about command-line compiler options. How do I programmatically obtain the Scala version inside code?
Alternatively, where does the Eclipse Scala plugin v2 store the path to scalac
?
This will work without access to scala-compiler.jar
:
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> util.Properties.versionString
res0: java.lang.String = version 2.9.1.final
scala.util.Properties.versionString
Feb 23, 2017 at 23:33
There are three ways to get the Scala version -
scala> util.Properties.versionNumberString
res103: String = 2.11.4
scala> util.Properties.versionString
res104: String = version 2.11.4
scala> util.Properties.versionMsg
res105: String = Scala library version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL
util.Properties.versionNumberString
only exist since scala 2.10.x. For scala below 2.10.x, you can use util.Properties.releaseVersion.getOrElse("unknown version")
to get version number string.
You can get the Scala version like this:
scala> scala.tools.nsc.Properties.versionString
res7: java.lang.String = version 2.9.0.final
I don't know the specifics of the plugin, though.
scala.tools.nsc.Properties.versionString
anywhere.
May 25, 2011 at 9:03
import scala.tools.nsc.Properties;
mine says "object tools is not a member of package ***.scala" :(
scala.tools...
is only available, if the scala-compiler.jar
is in the classpath.
May 25, 2011 at 9:35
We can also get installed Scala version
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_6 0). Type in expressions to have them evaluated. Type :help for more information.
scalac
; it invokes the compiler classes directly from within with Eclipse JVM.scala.sys.props
references what seems to be scala libraries under something likesun.boot.class.path -> F:\eclipse\configuration\org.eclipse.osgi\bundles\316\1\.cp\lib\scala-library.jar;
(withjar
'slibrary.proerties
containingversion.number=2.9.0.final
). But sincescala.sys.props
is in there since2.9.0
only it's pretty much a hint itself :)