10

I come from a background in Ruby, and I use RVM to manage multiple Ruby and gemsets. I have googled around, and I found these two SVM and PVM, not sure what should I use? Anyone can recommend what should I use to manage multiple scala?

PVM Play Version Manager https://github.com/kaiinkinen/pvm

SVM Scala Version Manager https://github.com/yuroyoro/svm

1 Answer 1

18

You don't need a version manager. You need a build tool.

Scala projects work differently than Ruby projects. If you use SBT as a build tool, you specify the Scala version in your build file:

//build.sbt

scalaVersion := "2.11.0" // or some other version

SBT then proceeds to download the specified Scala version for you if it hasn't been downloaded before, and builds and runs your project with this version. If you want, you can even specify which version of SBT you want, and it'll arrange everything for you as well.

This is because Scala, contrary to Ruby, is a compiled language - it must be compiled/built before running. Ruby projects don't have a build process, and can be (attempted to) run on any Ruby version. Scala projects might not build on incompatible versions, let alone run, so you need to specify which Scala version your project is supposed to be built against.

There's also no such thing as gemsets for Scala. For Ruby, gems were originally system-wide libraries and executables, shared by all Ruby scripts on the system. Therefore, gems override each other and you need to maintain gemsets with the specific versions you require for each project. In Scala, a dependency is just a library specifically for your project. They don't override each other, and you just specify which version you need in your build file. SBT then automatically downloads it for you when you build.

This just works:

// myproject1/build.sbt
scalaVersion := "2.10.2"

libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.2.0"


// myproject2/build.sbt
scalaVersion := "2.11.0"

libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.3"
3
  • 1
    Also note that sbt supports cross compilation, which means that in addition to specifying the primary Scala version to use, you can also tell sbt "please also create versions of my code that are built against these other versions of Scala", and sbt will automatically download those versions of Scala, as well as the versions of all your dependencies that were built against those versions of Scala. Of course, you can only build against older versions of Scala if your code doesn't rely on new language features that don't exist in the older versions.
    – reggert
    May 26, 2014 at 16:13
  • If I don't need a version manager for Scala, is there a version manager for SBT instead (if SBT introduces new features)?
    – whirlwin
    Oct 17, 2016 at 14:37
  • No. You can specify the version of sbt you wish to use (in a build.properties file) and any version of sbt will use the appriate version an features to build your project. See stackoverflow.com/questions/28429030/…
    – DCKing
    Nov 16, 2016 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.