These are chat archives for sbt/sbt

19th
Jul 2015
bjenkinsgit
@bjenkinsgit
Jul 19 2015 12:18
How can I control what version of the Scala REPL is invoked from the consoleProject command in SBT? If I start in a clean directory and type sbt consoleProject, I get a REPL with scala version 2.10.4. Even though I have SBT 0.13.8 installed! Is that normal behavior? I have even tried removing my .sbt directory in my home. When I do that and launch sbt I see the following (one-time) actions:
Getting org.scala-sbt sbt 0.13.8 ...
:: retrieving :: org.scala-sbt#boot-app
confs: [default]
52 artifacts copied, 0 already retrieved (17674kB/210ms)
Getting Scala 2.10.4 (for sbt)...
:: retrieving :: org.scala-sbt#boot-scala
confs: [default]
5 artifacts copied, 0 already retrieved (24459kB/77ms)
Notice it is pulling down version 2.10.4?
My concern is that sbt console gives me one version of Scala for the REPL but sbt consoleProject gives me a different one.
Josh Suereth
@jsuereth
Jul 19 2015 12:48
ConsoleProject starts a replacement against sbt. It's OK for your build to use a different version than your project
S/replacement / repl/
And you can't control that version. Sbt and all its plugins lock in one Scala version, so they are all binary compatible. Shouldn't affect the version for your project at all.
bjenkinsgit
@bjenkinsgit
Jul 19 2015 13:00
@jsuereth The whole reason I started looking hard at that was because I wanted to test something out in the REPL and was under the impression that if I started it with consoleProject that this would give me access to all the APIs listed in my plugins or build.sbt file. I was specifically trying to play with >boopickle from mr. ochrons ("me.chrons" %% "boopickle" % "1.1.0") and when I fired up either console or consoleProject and issued an import of import boopickle.Default._, I got a error: not found. How do I make a library known to the REPL inside of SBT if consoleProject does not do that for me automatically?
Josh Suereth
@jsuereth
Jul 19 2015 13:01
yes it will, those are all built against scala 2.10, (assuming plugins are defined in plugins.sbt)
If you just want to toy with library dependnecies you want to use consoleQuick or console
consoleProject is about testing your sbt build itself, i.e. the sbt plugins you're using and the sbt libraries
console or consoleQuick create a REPL for the project you're currently building
e.g. in consoleProject type name.eval and you'll see it tell you the name of your project.
bjenkinsgit
@bjenkinsgit
Jul 19 2015 13:09
ahh, ok. Is there a REPL command to pull in a library and make it available on the classpath such that I can import and use the API from that library, or is the only way to pass the library classpath to sbt when I start sbt?
Josh Suereth
@jsuereth
Jul 19 2015 13:16
If your build.sbt contains a libraryDependencies += ... or you have a jar in the lib/ folder, then running consoleQuick should boot up with that library on the classpath.
Pierre Dal-Pra
@pdalpra
Jul 19 2015 13:29
@bjenkinsgit you may be interested by http://lihaoyi.github.io/Ammonite/#Ammonite-REPL
bjenkinsgit
@bjenkinsgit
Jul 19 2015 13:29
That was my understanding also. But that doesn't seem to work. I've copied the boopickle.jar (boopickle_2.11-1.1.0.jar) into a lib folder in a clean directory, typed sbt, fired up consoleQuick and typed in the import statement of import boopickle._ and I still get the error. And I even extracted the contents of the jar to make sure my import statement was correct. I also tried invoking sbt via sbt -Dsbt.extraClasspath=path/to/boopickle.jar
But if that SHOULD work, I'll have to double check my environment.
Next test will be to see if I can get it working from a eclipse scala worksheet.
@pdalpra Thanks for that link, that does look interesting!
Pierre Dal-Pra
@pdalpra
Jul 19 2015 13:34
Note however that what ammonite-repo provides is only convenience
$ sbt
> set libraryDependencies += "me.chrons" %% "boopickle" % "1.1.0"
> console
Welcome to Scala version 2.11.7 (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> import boopickle._
import boopickle._

scala>
Pierre Dal-Pra
@pdalpra
Jul 19 2015 13:40
from an (almost) empty project (only set scalaVersion := “2.11.7” because boopickle doesn’t exist for Scala 2.10 and sbt sets the Scala version to the one it uses, e.g. 2.10.4 with sbt 0.13.8)
bjenkinsgit
@bjenkinsgit
Jul 19 2015 13:40
@pdalpra That was it! All I was missing was the interactive set libraryDependencies += "me.chrons" %% "boopickle" % "1.1.0" statement AFTER firing up sbt but BEFORE invoking console. Thanks!
Pierre Dal-Pra
@pdalpra
Jul 19 2015 13:40
you’re welcome :)
bjenkinsgit
@bjenkinsgit
Jul 19 2015 13:41
This message was deleted
This message was deleted
import boopickle.Default._

object BooPickleSandbox {
  val data = Seq("Hello", "World!")               //> data  : Seq[String] = List(Hello, World!)
  val buf = Pickle.intoBytes(data)                //> buf  : java.nio.ByteBuffer = java.nio.HeapByteBuffer[pos=0 lim=14 cap=1400]
  val helloWorld = Unpickle[Seq[String]].fromBytes(buf)
                                                  //> helloWorld  : Seq[String] = Vector(Hello, World!)
}