Why does SBT's Scala (2.10) not include Akka? - scala

I downloaded Scala 2.10.2, unpacked it and run Scala command, I can successfully import akka._.
In another experiment, I create an sbt project with the following line in build.sbt:
scalaVersion := "2.10.2"
A source file import akka._, and sbt complains "akka not found".
What is the difference betwen SBT's Scala 2.10.2 and the one on Scala website? And why does the official Scala already include Akka library, but SBT's Scala does not?

Akka is a part of the Scala Distribution (the zip you downloaded) but not the Scala Standard Library — which is what you get in SBT.

Related

NullPointerException on XML.loadFile()

I am trying to load an xml file using scala-xml_2.12-1.0.6.jar but it gives me NullPointerEexception while loading
Following is my line of code to load xml
import scala.xml.XML
val xml = XML.loadFile("sample.xml")
I have decompiled this jar and is method is present in that jar but for some reasons it is unable to find it in code.
I have Scala 2.13.1 on my system but for this project I am using scala 2.12.1 and it is mentioned in mu built.sbt
scalaVersion := "2.12.1"
I have following dependency in my built.sbt for this xml package
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.6"
If I copy and paste the same code to Scala interactive shell( scala 2.13.1) I get following error
import scala.xml.XML
^
error: object xml is not a member of package scala
did you mean Nil?
Can anyone please identify what am i doing wrong?
Thanks in advance.
I'm not sure how you are loading up the Scala REPL, but as mentioned in "How to use third party libraries with Scala REPL?", you should be launching the the REPL from SBT with sbt console. Your .sbt files will also need to be in scope.
The Scala REPL independently does not deal with .sbt files. They are 2 different tools.
Alternatively you could also install Ammonite-REPL which supports Magic Imports. You will be able to import Maven dependencies with import $ivy.
Scala 2.12 comes with scala-xml and you can remove that dependency as long as you run REPL with sbt console and not your native Scala REPL which is already # Scala 2.13. Otherwise you can also switch to Scala 2.13 for your SBT project.

Which version of SBT ? scala2.13.3

According to the SBT website, the latest version of SBT is 1.3.13. Is this available in 2.13.3, the latest version of Scala?
Yes.
You can download the latest version of sbt (1.3.13 for now)
https://www.scala-sbt.org/download.html
and use it for your project if you write in the file project/build.properties
sbt.version = 1.3.13
Also you can write in the file build.sbt
scalaVersion := "2.13.3"
Currently it's the latest version of Scala
https://www.scala-lang.org/download/all.html
So you will be using the latest versions both of Scala and sbt.
Some sideways remarks. Sbt is written in Scala itself. For sbt 1.3.13 it's Scala 2.12.10. Most probably this version of Scala is irrelevant to you. It's relevant only to those who develop sbt or write plugins to sbt etc. Also the file build.sbt is a script in Scala using version of Scala specified in project/build.sbt i.e. in the build file of meta-project (sbt is recursive). It should be Scala 2.12.x because of the binary compatibility with the version of Scala sbt is written in, i.e. from 2.12.0 to 2.12.12. So you can write val x: 1 = 1 (singleton types, a Scala-2.13 feature) in your project Scala code but can't in build.sbt. In this sense the answer is No.

SBT - How to mix/create separate Scala 2.11 and Scala 2.12 folders in same project?

I have an sbt project with deprecated libraries (ex. Spray, pre-release macro paradise, etc) that I cannot upgrade to Scala 2.12. It compiles with Scala 2.11.8 now. I want to continue development with non-deprecated libraries (ex. Akka HTTP, latest Scala macros, etc.) by creating a folder called "2.12" and a folder called "2.11" and putting the deprecated 2.11 code in the "2.11" folder and continuing development in the "2.12" folder. The code in the "2.12" folder can cross-compile with both Scala 2.11 and Scala 2.12, but the code in the "2.11" folder can only compile with Scala 2.11. I want to be able to mix the deprecated code and the non-deprecated code in the same project, at least at first, and gradually move things over to the "2.12" folder. How do I do that with sbt?
Right now the project uses sbt 0.13 and it won't compile with sbt 1.X, but if I clean/fix up the Build.scala file and maybe convert it to a build.sbt file, I think I will be able to upgrade from 0.13 to 1.X
It is possible to change the default Scala source directory via: https://www.scala-sbt.org/1.0/docs/Howto-Customizing-Paths.html

What's the relationship of the versions of scala when I use sbt to build a scala project?

I'm building a scala project(writen in scala 2.11) with SBT 1.x.There are a few "versions of scala" which made me puzzle.
SBT 1.x => scala 2.12
SBT plugin => scala 2.x
My project => scala 2.11
Please help me to figure out what's the difference or relationship between them.And how SBT tells them apart when compiling or running the project?
The Scala version used by sbt itself and its plugins is completely independent from the Scala version used to compile the code in your project. The sbt version determines the Scala version it uses:
sbt 0.13 uses Scala 2.10
sbt 1.x uses Scala 2.12
You can set this version in project/build.properties, for example:
sbt.version = 1.1.1
The sbt plugins you want to use have to be compatible with the given version of sbt (and many are cross-compiled with both 0.13 and 1.x).
To set the version of Scala you want to use for the code in you project, use scalaVersion setting in your build.sbt:
scalaVersion := "2.12.4"
Again, it's independent from the version for sbt. You can also cross-compile your code for several Scala versions:
scalaVersion := "2.12.4"
crossScalaVersions := Seq("2.11.12", "2.12.4")
Then if you run compile in sbt, it will use Scala 2.12.4, and if you run +compile, it will first compile it with Scala 2.11.12 and then with 2.12.4. See sbt docs for more about Cross-building.

How to make intellij import scala project with scala 2.11.7 (as per build.sbt)?

I'm having problems with my project which I think are due to intellij pulling in a load of scala 2.10 libraries when it created/if I reimport my project.
How can I configure it to either read the version of scala from build.sbt, or manually configure it to compile with scala 2.11.7? I'm running intellij IDEA 14 with the latest updates and it always uses scala 2.10.4.
Make sure you have your Scala Version set in your build.sbt
scalaVersion := "2.11.7"
The rest works seemlessly. Enable "Auto-Import" in IDEA when creating the project.
The 2.10 libraries are used by SBT itself. If you check the Dependencies tab for your modules, you shouldn't see them. If you do, you likely have an error in libraryDependencies in build.sbt.