How do I tell sbt to use local scala installation? - scala

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.

Related

SBT, Scala version mismatch

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.

How to install Scala software

I want to use a tool written by Scala but I have no experience with Scala.
The tool I want to use is from https://github.com/allenai/pdffigures2. It told me how to install the tool in the readme but I can not understand.
It said I need
resolvers += Resolver.bintrayRepo("allenai", "maven")
And then include
libraryDependencies += "org.allenai" %% "pdffigures2" % "0.0.11"
what does that mean, where should I add them? I am on Ubuntu. It would be kind if someone can tell me how to install this tool step by step, currently, there is not Scala in my computer.
Install sbt (Scala build tool) from here: http://www.scala-sbt.org/
Create a new Project with
sbt new scala/scala-seed.g8
cd <project_name>
vi build.sbt
Add your lines to this build.sbt. After that you can use the commands given in the section "Command Line Tools" of pdffigures2
Edit: Just saw that the library is only available for Scala 2.11. Could you change the scala version in build.sbt as follows:
scalaVersion := "2.11.11",

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.

How can I force which Scala version SBT should use?

I keep getting the error
Error while loading AnnotatedElement, class file
'/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar(java/lang/reflect/AnnotatedElement.class)'
is broken
When running SBT against my project. It appears this error is due to this problem with Scala 2.10 not working with JDK 8. I do have scala 2.11 set and my SCALA_HOME points to Scala 2.11 at "SCALA_HOME=/Library/Scala/scala-2.11.2".
So any idea how to force SBT to use this version or check what version it is currently trying to use?
In your Build.sbt change the Scala version specified to the version you want (it defaults to what SBT was built with)
scalaVersion := "2.11.2"
http://www.scala-sbt.org/release/docs/Howto-Scala.html
Add to the build.sbt this line:
scalaVersion := "2.11.2"

how to configure 2.9.1 in org.scala-sbt#sbt_2.9.1;0.12.3

I am trying a very simple sbt example; when I compile it with sbt, and always get the following error:
org.scala-sbt#sbt_2.9.1;0.12.3: not found
I found a build.properties file under project folder, where I could change the 0.12.3 part; for example, after I changed it to 0.11.3, it will succeed until another inompatible issue; However, I want to know how to change sbt_2.9.1 to, say, sbt_2.9.2; I don't find a configuration file, and even I update the sbt to the latest version 0.12.3, still no luck.
my build.sbt file:
organization := "com.typesafe.slick"
name := "slick-examples"
version := "1.0.1-RC1"
scalaVersion := "2.10.1"
scalacOptions += "-deprecation"
anyone please help me.
The Scala version sbt is using internally and the one used for your project are totally independent. Which sbt launcher are you using? Make sure you are using an sbt.version property that works for your sbt launcher.
Again, no need to configure the Scala version for your project at that level. Write a build.sbt file and set scalaVersion to, e.g. 2.10.1 (assuming you use sbt 0.12.x): scalaVersion := 2.10.1