My project used scala version 2.10.2. I am trying to update to 2.11.4. I have updated my build.sbt. But now when I run sbt compile it still shows me Resolving org.scala-lang#scala-library;2.10.2 .... I believe it means that my scala version hasn't been updated. What am I doing wrong?
I hope I have made my question clear. If there is any confusion then please ask. Thanks in advance.
You can always use show to see the value of any setting:
% sbt
[info] Loading project definition from ...
[info] Set current project to ...
> show scalaVersion
[info] 2.12.0-M1
scalaVersion tells you which Scala version your project is built with. You can also verify it using console:
> console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.12.0-M1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> scala.util.Properties.versionString
res0: String = version 2.12.0-M1
This may be different from the Scala version used to compile your build definition. sbt 0.13 always uses Scala 2.10 for that:
> eval scala.util.Properties.versionString
[info] ans: String = version 2.10.4
You can't change that; it's determined by the sbt version.
Related
I'm trying to get Scala set up for a Coursera course on Ubuntu, and I've followed their instructions by installing open-jdk 1.8, sbt (sbt about says v1.0.2), and IntelliJ Idea. I've set up an sbt project with a HelloWorld Scala worksheet in src/main/scala that just says "Hello, world", but when I try to evaluate the worksheet, I get the error
Internal error: Scala instance doesn't exist or is invalid: version unknown, library jar: /home/[my username]/.ivy2/cache/jline/jline/jars/jline-2.14.5.jar, compiler jar: /home/[my username]/.ivy2/cache/org.scala-lang.modules/scala-xml_2.12/bundles/scala-xml_2.12-1.0.6.jar
followed by a longer trace. Is there a setup step I'm missing? The project seems to point to Java v1.8 in the Project Structure dependencies, and in the "Libraries" tab I see SBT set to Scala v2.12.
I've just had the same problem with macOS Sierra.
I solved after noticing that in my build.sbt I had:
name := "myScalaTests"
version := "0.1"
scalaVersion := "2.12.4"
but prompting sbt about, my scala version was different.
sbt about
[warn] No sbt.version set in project/build.properties, base directory: /Users/myUser/projects
[info] Set current project to projects (in build file:/Users/myUser/projects/)
[info] This is sbt 1.0.2
[info] The current project is {file:/Users/myUser/projects/}projects 0.1-SNAPSHOT
[info] The current project is built against Scala 2.12.3
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, sbt.plugins.Giter8TemplatePlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.12.3
so I changed the version of scala in the build.sbt accordingly, ant it worked.
The same internal error can be caused by a version mismatch between the sbt launcher and the project sbt version, as described here:
Internal error: Scala instance doesn't exist or is invalid
In my project, there was no scala version mismatch, but downloading the latest sbt launcher and restarting my session resolved the issue.
I use:
scala version 2.11.8 everywhere in the project, this version is explicitly specified in build.sbt
sbt version 0.13.13, which specified both in project/build.properties and IDE settings
IntelliJ IDEA uses the correct version of scala for tests running and project building (output is in ...target/scala-2.11...), but not for play2 application. The latter one for some reason uses scala 2.10: [info] Compiling 86 Scala sources to .../target/scala-2.10/classes....
The only idea I have is that IDEA uses the default scala of the sbtlauncher (it uses 2.10.6 when run from console), despite the explicit declaration in build file.
I'm trying to create an RStudio-like experience for Scala and spark. After figuring out how to install it properly (including Scala 2.10.5) on Win7x64, I'm facing the problem, that the version of the interpreter
scala> scala.tools.nsc.Properties.versionString
res1: String = version 2.11.8
differs from the spark-shell scala version
scala> scala.tools.nsc.Properties.versionString
res1: String = version 2.10.5
and from the scala version (cmd.exe)
C:\>scala -version
Scala code runner version 2.10.5 -- Copyright 2002-2013, LAMP,EPFL
Which causes my problems according to this answer problems when starting spark from the interpreter
scala> val sc = new SparkContext(conf)
java.lang.NoSuchMethodError: scala.
collection.immutable.HashSet$.empty()Lscala/collection/immutable/HashSet;
Question: Where do I set/configure the version the interpreter uses? Searching the global settings of the Scala IDE for "interpreter" gave no results. Seems to be something that was shipped along with the Scala IDE?
(spark 1.6.1, hadoop 2.6, Scala IDE 4.4.1, Scala 2.10.5, at least that's the way it should be)
Instead of using a specific scala REPL installation, you can always use sbt console and a build.sbt file to spin up the correct version.
If you add a build.sbt file to your main directory, Scala IDE should pick up on the version you want to be using.
~/test2$ cat build.sbt
scalaVersion := "2.11.7"
~/test2$ sbt console
[info] Set current project to test2 (in build file:/projects/9ab40ff8-31cd-4860-9cc9-ceb67d1afa39/test2/)
[info] Updating {file:/projects/9ab40ff8-31cd-4860-9cc9-ceb67d1afa39/test2/}test2...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.11.7 (OpenJDK 64-Bit Server VM, Java 1.7.0_101).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :q
[success] Total time: 24 s, completed Jun 16, 2016 9:18:19 PM
~/test2$ echo 'scalaVersion := "2.10.5"' > build.sbt
~/test2$ cat build.sbt
scalaVersion := "2.10.5"
~/test2$ sbt console
[info] Set current project to test2 (in build file:/projects/9ab40ff8-31cd-4860-9cc9-ceb67d1afa39/test2/)
[info] Updating {file:/projects/9ab40ff8-31cd-4860-9cc9-ceb67d1afa39/test2/}test2...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] 'compiler-interface' not yet compiled for Scala 2.10.5. Compiling...
[info] Compilation completed in 61.292 s
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.5 (OpenJDK 64-Bit Server VM, Java 1.7.0_101).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :q
[success] Total time: 77 s, completed Jun 16, 2016 9:20:45 PM
You can also specify library dependencies from places like mvnrepository and sbt will download them (if not already downloaded) and add them to your REPL classpath.
As a final aside, check out Jupyter Scala for an Ipython-esque notebook interface for Scala.
When I install the latest version of sbt (v0.13.9) and then run the following to download scala and associated libraries:
jdoe$ sbt test
jdoe$
jdoe$ sbt console
[info] Set current project to nmvega (in build file:/home/jdoe/)
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
I get Scala version 2.10.5, as seen above.
How can I get sbt to build with (or use a separately installed) scala version, say v2.12.0-M3 ? I can't find instructions for this.
Thank you in advance.
As you can see in documentation SBT provides many ways to Configure and use Scala
Set the Scala version used for building the project
The scalaVersion configures the version of Scala used for compilation. By default, sbt also adds a dependency on the Scala library with this version. See the next section for how to disable this automatic dependency. If the Scala version is not specified, the version sbt was built against is used. It is recommended to explicitly specify the version of Scala.
For example, to set the Scala version to "2.9.2",
scalaVersion := "2.9.2"
Disable the automatic dependency on the Scala library
sbt adds a dependency on the Scala standard library by default. To disable this behavior, set the autoScalaLibrary setting to false.
autoScalaLibrary := false
Temporarily switch to a different Scala version
To set the Scala version in all scopes to a specific value, use the ++ command. For example, to temporarily use Scala 2.8.2, run:
> ++ 2.8.2
Use a local Scala installation for building a project
Defining the scalaHome setting with the path to the Scala home directory will use that Scala installation. sbt still requires scalaVersion to be set when a local Scala version is used. For example,
scalaVersion := "2.10.0-local"
scalaHome := Some(file("/path/to/scala/home/"))
Can you post your build.sbt please.
You should be able to declare the Scala by adding the following to build.sbt file
scalaVersion := "2.11.7"
When using the Scala interpreter, one could start it with an option like:
C:\Users\John>scala -unchecked
Welcome to Scala version 2.9.2 (Java HotSpot(TM) Client VM, Java 1.6.0_32).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
When using sbt, how can one start the Scala interpreter with options ?
The following try will not work:
C:\Users\John\Test Scala Project 1>sbt
[...]
[info] Loading global plugins from C:\Users\John\.sbt\plugins
[info] Set current project to default-8d4ecc (in build file:/C:/Users/John/Tes
t%20Scala%20Project%201/)
> console -unchecked
[error] Expected end of input.
[error] console -unchecked
[error] ^
With Google & Co I could not figure out how to do this from within the sbt shell. Does anyone know ?
dcs#shadowfax:~/github/ConwayLife (master *)$ sbt
[info] Loading global plugins from /home/dcs/.sbt/plugins/project
[info] Loading global plugins from /home/dcs/.sbt/plugins
[info] Loading project definition from /home/dcs/github/ConwayLife/project
[info] Set current project to default-0d85ea (in build file:/home/dcs/github/ConwayLife/)
default-0d85ea:master>set scalacOptions += "-unchecked"
[info] Reapplying settings...
[info] Set current project to default-0d85ea (in build file:/home/dcs/github/ConwayLife/)