鉴于我有build.sbt
name := """app"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
// <-- some other code -->
import Fixtures._
lazy val fixtures = inputKey[Unit]("Generating Cassandra fixtures")
fixtures := {
Fixtures.generate()
}
和project
目录中的Fixtures.scala
object Fixtures {
def generate (): Unit = {
println("generating fixtures")
}
}
我可以运行命令./activator fixtures
,我正在&#34;生成灯具&#34;
但是如何调用某些服务,比如GenerateUserFixtureService.scala
来自app/scala/com/MyProject/Service
目录。导入包不起作用,因为project
目录属于不同的包。我无法从Play
Fixtures.scala
导入任何内容
|
|___app
| |__scala
| |__com
| |__MyProject
| |__Service
| |--GenerateUserFixtureService.scala
|___project
| |--Fixtures.scala
|___
|--build.sbt
实际上问题是,为什么我只能从build.sbt
目录导入project
个文件。或者如何从app
dir调用另一个文件?
或许我想的方式完全错了。我只是想创建一些命令upload:fixtures
send:emails
等,并调用一些scala类。我怎样才能做到这一点?
答案 0 :(得分:8)
要创建自定义命令,必须指定与命令逻辑对应的函数。我们来看几个例子: 首先打印你好消息:
def helloSbt = Command.command("hello") { state =>
println("Hello, SBT")
state
}
commands += helloSbt
只需将此代码放入build.sbt
,commands
为project key
,sbt.Keys
为val commands = SettingKey[Seq[Command]]
当然,您可以像成功或失败一样管理命令语句:
def failJustForFun = Command.single("fail-condidtion") {
case (state, "true") => state.fail
case (state, _) => state
}
您可以通过利用DefaultParsers
来改变控制台特定部分或该命令输出的控制台颜色:
lazy val color = token( Space ~> ("blue" ^^^ "4" | "green" ^^^ "2") )
lazy val select = token( "fg" ^^^ "3" | "bg" ^^^ "4" )
lazy val setColor = (select ~ color) map { case (g, c) => "\033[" + g + c + "m" }
另外,您可以扩展xsbti.AppMain
并实施 - your own logic