我有一个使用 scala 的 play 2.8.x 应用程序。
sbt 项目有一个 play web 项目和另一个库模块。
是否可以与 REPL 中的其他模块进行交互?我的系统上也安装了 ammonite,但不知道如何加载我的模块。我只需要构建然后在我的 /target 构建文件夹中引用该库吗?或者,还有更好的方法?
我可以自己在 sbt 中执行此操作还是 ammonite 是唯一的方法?
我有一个使用 scala 的 play 2.8.x 应用程序。
sbt 项目有一个 play web 项目和另一个库模块。
是否可以与 REPL 中的其他模块进行交互?我的系统上也安装了 ammonite,但不知道如何加载我的模块。我只需要构建然后在我的 /target 构建文件夹中引用该库吗?或者,还有更好的方法?
我可以自己在 sbt 中执行此操作还是 ammonite 是唯一的方法?
每个 sbt 项目都有一个 REPL,你只需要运行:
sbt> console
对于根项目或name
项目
sbt> name/console
但这是正常的 Scala REPL,如果你想要 ammonite,那么 ammonite.io上有说明:
您还可以在现有的 SBT 项目中试用 Ammonite 2.1.4。为此,请将以下内容添加到您的 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}
}
之后,只需点击
sbt projectName/test:run
或者如果测试范围内还有其他主要方法
sbt projectName/test:run-main amm