Skip to content

Instantly share code, notes, and snippets.

@ymasory
Created April 17, 2011 00:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ymasory/923640 to your computer and use it in GitHub Desktop.
Save ymasory/923640 to your computer and use it in GitHub Desktop.
detect Scala version at runtime
def getRunningScalaVersion(): String = {
try {
//OLD WAY
//val stream = getClass.getResourceAsStream("/library.properties")
//val iter = scala.io.Source.fromInputStream(stream).getLines
//val line = (iter find {l => l.startsWith("version.number")}).get
//val Version = """version\.number=(\d\.\d\.\d).*""".r
//stainsby's way
val props = new java.util.Properties
props.load(getClass.getResourceAsStream("/library.properties"))
val line = props.getProperty("version.number")
val Version = """(\d\.\d\.\d).*""".r
val Version(versionStr) = line
versionStr
}
catch {
case e => {
e.printStackTrace()
"2.8.0" //or some other default version, or re-raise
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment