How do I get the Scala version from within Scala itself?

ScalaVersion

Scala Problem Overview


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?

Scala Solutions


Solution 1 - Scala

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

Solution 2 - Scala

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

Solution 3 - Scala

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.

Solution 4 - Scala

We can also get installed Scala version

  1. Open command prompt
  2. type Scala
  3. You will get following output:

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmlvljrView Question on Stackoverflow
Solution 1 - ScalaPaul ButcherView Answer on Stackoverflow
Solution 2 - ScalaNaga VijayapuramView Answer on Stackoverflow
Solution 3 - ScalaHairyFotrView Answer on Stackoverflow
Solution 4 - ScalaChinyaView Answer on Stackoverflow