Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sbt `console` use -Yrepl-sync?

New in Scala 2.9.1 is the -Yrepl-sync option, which prevents each REPL line from being run in a new thread:

scala -Yrepl-sync

When I run console from sbt, how do I have it pass this in?

like image 528
Yang Avatar asked Sep 30 '11 19:09

Yang


People also ask

What is sbt console?

SBT is tied to a specific project defined by a build. sbt file in a way that $ sbt console will load up the same REPL environment as $ scala but with the addition of all of the project code and dependencies defined in the build available for import. Also, it will use the version of Scala defined by build. sbt .

How do I run a Scala program in terminal?

Executing Scala code as a script Another way to execute Scala code is to type it into a text file and save it with a name ending with “. scala”. We can then execute that code by typing “scala filename”. For instance, we can create a file named hello.

How do I run a Scala command line?

To run Scala from the command-line, download the binaries and unpack the archive. Start the Scala interpreter (aka the “REPL”) by launching scala from where it was unarchived. Start the Scala compiler by launching scalac from where it was unarchived.


1 Answers

Short answer:

set scalacOptions in (Compile, console) += "-Yrepl-sync"

How to discover this:

~/code/scratch/20110930 sbt
[info] Loading global plugins from /Users/jason/.sbt11/plugins
[info] Set current project to default-9c7c16 (in build file:/Users/jason/code/scratch/20110930/)
> inspect console
[info] Task: Unit
[info] Description:
[info]  Starts the Scala interpreter with the project classes on the classpath.
[info] Provided by:
[info]  {file:/Users/jason/code/scratch/20110930/}default-9c7c16/compile:console
[info] Dependencies:
[info]  compile:compilers(for console)
[info]  compile:full-classpath
[info]  compile:scalac-options(for console)
[info]  compile:initial-commands(for console)
[info]  compile:streams(for console)
[info] Delegates:
[info]  compile:console
[info]  *:console
[info]  {.}/compile:console
[info]  {.}/*:console
[info]  */compile:console
[info]  */*:console
[info] Related:
[info]  test:console
> set scalaVersion := "2.9.1"          
[info] Reapplying settings...
[info] Set current project to default-9c7c16 (in build file:/Users/jason/code/scratch/20110930/)
> set scalacOptions in (Compile, console) += "-Yrepl-sync"
[info] Reapplying settings...
[info] Set current project to default-9c7c16 (in build file:/Users/jason/code/scratch/20110930/)
> console
[info] Updating {file:/Users/jason/code/scratch/20110930/}default-9c7c16...
[info] Done updating.
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :power
** Power User mode enabled - BEEP BOOP SPIZ **
** :phase has been set to 'typer'.          **
** scala.tools.nsc._ has been imported      **
** global._ and definitions._ also imported **
** Try  :help,  vals.<tab>,  power.<tab>    **

scala> settings
res1: scala.tools.nsc.Settings = 
Settings {
  -classpath = /Users/jason/code/scratch/20110930/target/scala-2.9.1/classes:/Users/jason/.sbt11/boot/scala-2.9.1/lib/scala-compiler.jar:/Users/jason/.sbt11/boot/scala-2.9.1/lib/jansi.jar:/Users/jason/.sbt11/boot/scala-2.9.1/lib/jline.jar
  -d = .
  -Yrepl-sync = true
  -encoding = UTF-8
  -bootclasspath = /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar:/System/Librar...
like image 59
retronym Avatar answered Sep 24 '22 21:09

retronym