SBT, Scala version mismatch - scala

i have installed Scala 2.11.8 version, and i installed SBT 0.13.12 version as well.
when i create one directory and inside that directory typed sbt and sbt prompt opened. Inside SBT prompt, when i checked libraryDependencies i found like this:
sbt:sparkp> libraryDependencies
[info] * org.scala-lang:scala-library:2.12.4
But in machine, i have installed scala 2.11.8 version, when i checked scala -version it shows
hadoop#localhost:~$ scala -version
Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL
Did i made any mistake while installing sbt? or i need to change any configuration properties after installation?
please help out.
Note: There are some questions regarding this error in stackoverflow, but i didn't get exact answer that's why i am asking new question.

In my opinion the scala version you are getting is the version with which sbt is built with.
The solution to your is to find global.sbt file which is usually in ~/.sbt/<version>/global.sbt
and add following line
scalaVersion := "2.11.8"
Your problem should be solved.

The Scala version of a project in SBT is completely unrelated to one you have installed and available from command line. This is a very good thing for several reasons:
Everyone who builds a project doesn't get different result depending on Scala version they have installed.
You don't need to install multiple Scala versions and switch between them all the time to work on multiple projects.
Many projects should be built with multiple Scala versions, see http://www.scala-sbt.org/0.13/docs/Cross-Build.html.
If you are creating a new project, you should specify scalaVersion := "2.11.8" (or any other you want) in build.sbt in this project.

Related

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.

sbt is using wrong scala version rather than using the configuration in build.sbt

I have put these in the build.sbt file under current project's root directory
scalaHome := Some(file("/Users/ddam/scala-2.10.2"))
scalaVersion := "2.10.2"
And I ran sbt using
$ sbt --version
sbt launcher version 0.12.4
But still, I am seeing both the wrong version for sbt and scala when a particular dependency cannot be resolved
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.typesafe.sbteclipse:sbteclipse-plugin:2.4.0 (sbtVersion=0.12, scalaVersion=2.9.2)
Please help me.
It looks like sbteclipse requires SBT 0.13.0, and you are using version 0.12.4.
You can specify the SBT version by following the directions on this page.
Some other notes: You probably want to use Scala 2.10.3, not 2.10.2.
Also, it's strange to specify scalaHome; usually SBT will automatically fetch the needed Scala jars for you.
So to bootstrap a Scala environment, all you need to have installed are SBT and a JDK.
EDIT: (addressing comment below):
When you build code with SBT, you may actually use two different versions of Scala.
There is the version for SBT (what version of Scala the build system runs on), and the version for the code in your project (what version of Scala your code will run on).
The Scala version for SBT is determined by the SBT version you use.
If you use 0.12.4, SBT will run on Scala 2.9.3.
If you use 0.13.0, SBT will run on Scala 2.10.3.
You control the SBT version by following these instructions.
To control the version of Scala your project will run on, you can set scalaVersion in <projectRoot>/build.sbt.
So, you're getting that error because you're using SBT 0.12.4, which uses Scala 2.9.3.
SBT tries to find the sbteclipse plugin for 2.9.3, but it doesn't exist because it requires SBT 0.13.0 (=> Scala 2.10.3).
It seems you've correctly specified the use of Scala 2.10.2 for compiling your project.
sbt 0.12.4 always uses Scala 2.9.x to compile the build files (i.e. build.sbt and the stuff under project/). This means that plugins for sbt 0.12.x must also be compiled against 2.9.x, which explains what you're seeing.
sbteclipse 2.4.0 requires sbt 0.13. Try sbteclipse 2.2.0 if you want to stay on sbt 0.12.4.
emchristiansen's answer has good additional points.

How do I tell sbt to use local scala installation?

Trying to learn how to use sbt and stuck with a situation: when I install sbt and run it for the first time, it tries to download scala 2.9.x into some directory inside my home. I have scala 2.10.2 installed somewhere else, so how do I tell sbt to use that scala distribution?
UPD.: Solution (this is distribution for sbt to use when building projects, but sbt will anyway download scala distribution needed for it itself):
***#***:~|⇒ cat .sbt/global.sbt
scalaVersion := "2.10.2"
scalaHome := Some(file("/usr/share/scala"))
You could copy the .jars of your distribution to ~/.ivy2/cache. But that would be totaly missing the point of using sbt. If you want to use scala 2.10.2, just put
scalaVersion := "2.10.2"
into your build.sbt, and it will download this version for you. Then if you want to update to 2.11 when it comes out, all you have to do is change a single line in your build.sbt.

sbt version and scala version. project configuration for intellij idea with sbt-idea plugin

I follow these steps to configure a project for IntelliJ idea.
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0")
I use sbt-idea for sbt version 0.12 with fixed bug for Idea.
When I type sbt in my project's directory, I noticed that it uses scala 2.9.2.. but I'm going to use scala 2.10.1 for my project.
Questions:
Does it make sense which scala version to use for plugin(s) (~/.sbt/plugins)-compilation, or I should use one/same scala version for everything? Can I change scala version for plugins?
So, I created ~/.sbt/plugin/build.sbt file with mentioned content.
that version is out of date, it depends on sbt-idea 1.2.0-SNAPSHOT. The latest at the time of writing is 1.3.0
See my project skeleton for an implementation using the latest versions of scala, scalatest and SBT to IDE project plugins.
Actually I got it.
if you have a project with build.sbt (that uses 2.10.1 scala) file - as soon as you type sbt.. all dependencies will be downloaded into ~/.sbt folder - even scala compiler will be downloaded there (~/.sbt/boot). It could be even several version of scala: 2.10.1 and 2.9.2 for example.
and about sbt-idea and ~/sbt/plugins .. it could any scala version - depending on its build.sbt file, for example in my case:
resolvers += "Sonatype snapshots" at
"http://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0-SNAPSHOT")
I should notice if try different version.. like 1.1.0-M2-TYPESAFE it will not work.. (at least in my case) - gen-idea command is not available then. I do not know why. I guess it should.
Also if you do not point resolvers += - it will will not work.. but it it will not tell you about that..
This plugin is using scala 2.9.2 - we can not see it here, but we can see it from that outputs it produces while installing/downloading. That's why we have ~/.sbt/boot/scala-2.9.2/ as a result.
In any case we should not care about it. It is handled by sbt.
When you converted your sbt-project into your intellij-idea project by typing gen-idea in sbt console, as the result your IDE project will be referencing to ~/.sbt/scala but not to your somewhere-installed-scala.. So even no need to pointing the scala location - that sbt-idea sbt's plugin will do all the work. And that's good!
That's the answer I wanted to get. One gets/understands it by trying it.

SBT 0.10 - remove dependency on Scala 2.8.1

My project uses Scala 2.9 so I've added
scalaVersion := "2.9.0-1"
to my build.sbt file, and run gen-idea. However IDEA still shows Scala 2.8.1 (in addition to 2.9) in External Libraries. Why, and how to remove it?
Your application will be compiled with whatever Scala version or versions you choose. However, SBT is also a Scala application, and it was compiled with Scala 2.8.1, so it needs Scala 2.8.1's libraries to work. This will not have any impact on your application.