0

I have a play 2.8.x application that uses scala.

The sbt project has a play web project and another library module.

Is it possible to interact with the other module in a REPL? I have ammonite installed on my system also, but not sure how to load my module. Do I just have to build and then reference the library in my /target build folder? Or is there a better way?

Can I do this in sbt by itself or ammonite is the only way?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

1 Answers1

1

Every sbt project has a REPL, you just have to run:

sbt> console

for root project or for name project

sbt> name/console

But this is normal Scala REPL, if you want ammonite, then there is instruction on ammonite.io:

You can also try out Ammonite 2.1.4 in an existing SBT project. To do so, add the following to your build.sbt

libraryDependencies += {
  val version = scalaBinaryVersion.value match {
    case "2.10" => "1.0.3"
    case _ ⇒ "2.1.4"
  }
  "com.lihaoyi" % "ammonite" % version % "test" cross CrossVersion.full
}

sourceGenerators in Test += Def.task {
  val file = (sourceManaged in Test).value / "amm.scala"
  IO.write(file, """object amm extends App { ammonite.Main.main(args) }""")
  Seq(file)
}.taskValue

// Optional, required for the `source` command to work
(fullClasspath in Test) ++= {
  (updateClassifiers in Test).value
    .configurations
    .find(_.configuration.name == Test.name)
    .get
    .modules
    .flatMap(_.artifacts)
    .collect{case (a, f) if a.classifier == Some("sources") => f}
}

After that, simply hit

sbt projectName/test:run

or if there are other main methods in the Test scope

sbt projectName/test:run-main amm 
Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64