How does sbt choose which Scala version to use? - scala

I have multiple projects in my sbt build. I'm trying to upgrade to Scala 2.10 from 2.9.1, so in my build.sbt file I put
scalaVersion := "2.10.0"
This seemed to work, because in my top-level project in sbt I get:
> scala-version
[info] 2.10.0
However, when I switch to one of the other projects:
> project web-client
[info] Set current project to web-client (in build file:/C:/Users/...
[web-client] $ scala-version
[info] 2.9.1
You see the version has now changed back to 2.9.1! How do I force the same Scala version to be used across all my projects?

I found out scoping the scalaVersion to ThisBuild will set it for all sub-projects. Details are here: http://www.scala-sbt.org/release/docs/Getting-Started/Multi-Project.html at the bottom, but here is what it says:
To set it only once, it is enough to write, in the main build.sbt file, the following line:
scalaVersion in ThisBuild := "2.10.0"

SBT has a default Scala version. You need to add the scalaVersion setting to all subprojects if you wish to change it. The most common way of doing that is having a "common settings" value that is added to all projects at the root level, through project/Build.scala.

Related

sbt console - set scala-version for all sub-projects

I have a multi-project build with scalaVersion := "2.11.8" for each module.
I want to run test and publish-local for Scala 2.12.0-RC1 without touching the build file. I thought the following would work:
$ sbt
> set scalaVersion in ThisBuild := "2.12.0-RC1"
> test
But that does not alter the Scala version used, sbt still compiles with Scala 2.11.8. This only works for single module builds (without project definitions).
How do I effectively override scalaVersion for all sub-modules from the sbt console?
Your attempt doesn't work because the setting for the module takes priority over the setting for ThisBuild; it would work if you used scalaVersion in ThisBuild in the build file instead of setting it separately for each module. I don't know if there is a way to do this with anything except scalaVersion, but:
As a final note, you can use ++ to temporarily switch the Scala version currently being used to build. should be either a version for Scala published to a repository, as in ++ 2.10.0 or the path to a Scala home directory, as in ++ /path/to/scala/home. See Command Line Reference for details.
> ++2.12.0-RC1
> test

Play Scala SBT not showing dependency in Reference Library in Eclipse

I created a new project using Play Scala and Eclipse. Added Squeryl dependency and see that it's been pulled during compile time. Confirmed it's present in .ivy2/cache/org.squeryl directory but eclipse project is not able to pull it up and causing compilation for import.
build.sbt
name := """registration"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws,
"org.squeryl" % "squeryl_2.10" % "0.9.6-RC2"
)
It looks like squeryl doesn't have a binary readily available for Scala 2.11 yet according to http://www.squeryl.org/getting-started.html
So if you want to use a pre-compiled version of this library you must change your scala version to 2.10.4.
All versions of squeryl available can be found at: http://mvnrepository.com/artifact/org.squeryl
I had a similar case using eclipse.
Select Project --> Clean to clean your workspace and build it again if you have not checked "Build Automatically".
If its still not visible please refresh the package explorer (or just the 'Referenced Library') with F5.

Play 2.3 run error

I'm experiencing a problem when running latest play framework 2.3.
It compiles just fine, although when I do activator run this error happens:
java.lang.NoSuchMethodError: scala.Predef$.ArrowAssoc(Ljava/lang/Object;)Ljava/lang/Object;
Full error log
I explicitly tried scalaVersion in every build.sbt file and it is the same.
I tried several things like activator clean, full removal os sbt caches and local repo sbt stuff, updating dependencies to latest version but no success.
I have scala version defined.
My current dependencies are:
I tried with both %% and force _2.11 in the name of the dependency.
Dependency List
Other important files
build.sbt
Common.scala
Dependencies.scala
When I fully clean caches it downloads scala 2.10.4 for no reason:
in this download log it says the sbt need the old scala.
Any idea why is this?
Any ideas?
Firstly, it does not matter which version of Scala is used to generate your build. The build system can use version 2.10.4, and that does not prevent your code from using version 2.11.1.
To look at the issue with your scala version, you should consider that settings added directly in build.sbt are added to the root project, but not to other projects. You can see this with a minimal project such as:
$ cat build.sbt
scalaVersion := "2.11.1"
lazy val subproj = project in (file("subproj"))
Then the output of sbt looks like this:
> show scalaVersion
[info] subproj/*:scalaVersion
[info] 2.10.4
[info] sbttest/*:scalaVersion
[info] 2.11.1
So, how can this be fixed?
We can create a lazy val containing a Seq[Setting[_]], and add it to the sub-project definition with the settings() method.
Here's an example build.sbt which adds the same settings to all projects:
$ cat build.sbt
lazy val root = project.in(file("."))
.aggregate(subproj)
.dependsOn(subproj)
.settings(commonSettings: _*)
lazy val subproj = project.in(file("subproj"))
.settings(commonSettings: _*)
lazy val commonSettings = Seq(
scalaVersion := "2.11.1"
)
The _* is required because settings() is defined as requiring Setting[_]* rather than Seq[Setting[_]], so _* converts between the two types. See also: What does param: _* mean in Scala?
And the output from sbt is:
> show scalaVersion
[info] subproj/*:scalaVersion
[info] 2.11.1
[info] root/*:scalaVersion
[info] 2.11.1
This approach can easily be applied to your build.
You're defining your dependencies in the wrong way.
When using SBT, don't use:
"org.mydep" % "mydep_2.11" % "1.0.0"
Instead use:
"org.mydep" %% "mydep" % "1.0.0"
The %% operator automatically appends the current Scala version of the current build. If you use dependencies built against other Scala versions, you're going to be getting the weird errors.
Also make sure you explicitly specify your Scala version somewhere:
scalaVersion := "2.11.1"
The problem was related to some manually added jars that I discovered in the lib folder, that were causing issues with the dependencies of the project defined in the build.sbt.
The only way to find out was to generate a activator dist and look for similar dependencies with different versions since in the dependency graph there were no conflicts

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

Why does SBT 0.12.2 resolve plugins with Scala 2.9.2 and ignore scalaVersion in build.sbt?

SBT 0.12.2 always attempts to resolve plugins using Scala 2.9.2 when using the %% syntax on plugin imports.
I have tried setting older versions of Scala in build.sbt, newer versions, etc. Even deleting target folder each time... nothing seems to make a difference.
name := "Game"
version := "1.0"
scalaVersion := "2.9.1" // SBT is ignoring the scala version
SBT is recursive, so you need to specify scala version for project, that build your project. Another words, you need to add appropriate scalaVersion to the plugins.sbt file.
For all plugins in your project, you set scalaVersion in project/plugins.sbt file that configures the build project definition for your project and where you define plugins.
$ cat project/plugins.sbt
scalaVersion := "2.9.3"
There's however a way to set up a more specific version of sbt and Scala for a plugin.
Instead of using addSbtPlugin that accepts a single ModuleID (constructed with % and %%), use addSbtPlugin(dependency: ModuleID, sbtVersion: String) or even addSbtPlugin(dependency: ModuleID, sbtVersion: String, scalaVersion: String), e.g.
$ cat project/plugins.sbt
// It doesn't exist and it's only for demo purposes
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.0", "0.12.2", "2.5")