Search code examples
scalaconfigurationread-eval-print-loop

How to run scala code on scala console start?


Is it possible to run some scala code each time the scala console repl starts (this code has to change the REPL context)?

Was expecting there might be some .scala or similar config file which would allow setting that.

My use case is running this code on each REPL start: https://stackoverflow.com/a/6770870/750216


Solution

  • name := "scala-playground"
    version := "0.1-SNAPSHOT"
    organization := "org.reactormonk"
    scalaVersion := "2.11.7"
    
    resolvers ++= Seq(
      "ScalaNLP Maven2" at "http://repo.scalanlp.org/repo",
      "Scala Tools Snapshots" at "http://scala-tools.org/repo-snapshots/",
      "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
    )
    
    libraryDependencies ++= Seq(
      "org.scalatest" %% "scalatest" % "2.2.1",
      "io.argonaut" %% "argonaut" % "6.1",
      "com.github.alexarchambault" %% "argonaut-shapeless_6.1" % "1.0.0-M1",
      "com.github.pathikrit"  %% "better-files-akka"  % "2.15.0"
    )
    
    javaOptions += "-Xmx4g"
    addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.7.1")
    initialCommands in console := """
    import scalaz._, Scalaz._
    //import shapeless._
    """