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/)
Related
On a Windows machine, I am running through the getting started tutorial here: https://www.scala-sbt.org/1.x/docs/sbt-by-example.html
I am able to start the sbt shell and compile but using the run command just hangs and I am forced to Ctrl-C to exit sbt.
Running scala against the JAR file directly also works as expected.
Sample output is the following:
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from S:\foo-build\project
[info] Loading settings for project foo-build from build.sbt ...
[info] Set current project to foo-build (in build file:/S:/foo-build/)
[info] sbt server started at local:sbt-server-8c6933abcb6848dbd242
sbt:foo-build> about
[info] This is sbt 1.2.8
[info] The current project is ProjectRef(uri("file:/S:/foo-build/"), "foo-build") 0.1.0-SNAPSHOT
[info] The current project is built against Scala 2.12.7
[info] Available Plugins
[info] - sbt.ScriptedPlugin
[info] - sbt.plugins.CorePlugin
[info] - sbt.plugins.Giter8TemplatePlugin
[info] - sbt.plugins.IvyPlugin
[info] - sbt.plugins.JUnitXmlReportPlugin
[info] - sbt.plugins.JvmPlugin
[info] - sbt.plugins.SbtPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.12.7
sbt:foo-build> compile
[success] Total time: 0 s, completed Feb 7, 2019 4:40:45 PM
sbt:foo-build> run
Terminate batch job (Y/N)? Y
This is enough of an answer for my own purposes.
I was able work around this issue by adding a line to my build.sbt file. After adding ThisBuild / scalaVersion := "2.12.8" I was able to use the run command. Following the tutorial linked in the main question I would not expect to have to do this but perhaps someone could shed some light.
I have been trying to use ensime with sublime to use Scala. To install ensime I created a plugin.sbt in this location
~/.sbt/1.0/plugins/plugins.sbt
here is the screen shot
I also added "addSbtPlugin("org.ensime" % "sbt-ensime" % "2.0.1")" in the plugin.sbt. But when I run sbt and run the command "ensimeConfig" to create .ensime file I get error
C:\Users\Mahadi>sbt
"C:\Users\Mahadi\.sbt\preloaded\org.scala-sbt\sbt\"1.0.1"\jars\sbt.jar"
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; sup
port was removed in 8.0
[info] Loading global plugins from C:\Users\Mahadi\.sbt\1.0\plugins\project
[info] Loading settings from plugins.sbt ...
[info] Loading global plugins from C:\Users\Mahadi\.sbt\1.0\plugins
[info] Loading project definition from C:\Users\Mahadi\project
[info] Set current project to mahadi (in build file:/C:/Users/Mahadi/)
[info] sbt server started at 127.0.0.1:5547
sbt:mahadi> ensimeConfig
[error] Not a valid command: ensimeConfig
[error] Not a valid project ID: ensimeConfig
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: ensimeConfig
[error] ensimeConfig
[error] ^
sbt:mahadi>
So I am looking for your help.
Youn should run sbt in the root directory of your sbt project, as the ensime configuration file is built based on it.
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.
I created a new project using Typesafe Activator. In the command prompt I execute the command activator dependencies. This results in:
E:\sample_app>activator dependencies
[info] Loading project definition from E:\sample_app\project
[info] Updating {file:/E:/sample_app/project/}sample_app-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to sample_app (in build file:/E:/sample_app/)
[error] Not a valid command: dependencies
[error] Not a valid project ID: dependencies
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: dependencies (similar: all-dependencies, rpm-dependencies, allDependencies)
[error] dependencies
[error] ^
Versions used:
Java version is 1.8.0_51,
Activator is 1.3.6,
OS is windows 8,
64 - bit OS.
Analysis
First, dependencies is not valid sbt commands. (All sbt commands can be used also in activator.)
Solution
Either you mean libraryDependencies (which is an sbt setting) so call
activator libraryDependencies
Or you want to see the classpath of the dependencies ( a sbt task, so you need to use show to see the output of the sbt task), e.g.
activator "show dependencyClasspath"
Edit as of 2015-09-30,3:50am
If calling from console, the combined command must be put into quotes. Here: "show dependencyClasspath"
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.