1

我正在开发一个带有自定义命令行界面的 sbt 启动应用程序。问题是每次我想测试它时,我都必须删除以前发布的目录,然后重新编译并在本地发布人工制品,然后最后运行应用程序并手动测试它。其中一部分是通过运行外部 shell 脚本来完成的。boot

我怎么能sbt为我做这份工作?我已经为它制作了骨架命令:

  lazy val root = Project(
    id       = "app",
    base     = file("."),
    settings = buildSettings ++ Seq( resolvers := rtResolvers,
      libraryDependencies ++= libs,
      scalacOptions  ++= Seq("-encoding", "UTF-8", "-deprecation", "-unchecked"),
      commands ++= Seq(launchApp))
  )


  val launchApp = Command.command("launch") { state =>
    state.log.info("Re-launching app")
    state
  }
4

1 回答 1

0
  1. 创建启动器配置文件,例如fqb.build.properties在项目的主目录中。

  2. 创建启动应用程序的脚本

    #!/usr/bin/env bash
    
    java -jar /path/to/sbt-launch.jar "$@"
    
  3. 定义任务和命令:

    lazy val launcherTask = TaskKey[Unit]("launch", "Starts the application from the locally published JAR")
    
    lazy val launchApp: Seq[Setting[_]] = Seq(
        commands += Command.command("publish-launch") { state =>
        state.log.info("Re-launching app")
        val modulesProj = modules.id
        s"$modulesProj/publishLocal" ::
          "publishLocal" ::
          launcherTask.key.label ::
          state
      },
      launcherTask := {
        "launch @fqb.build.properties" !<
      }
    )
    
  4. 将其作为设置添加到项目中:

    lazy val root = Project(
        id       = "app",
        base     = file("."),
        settings = buildSettings ++ Seq( resolvers := rtResolvers,
          libraryDependencies ++= libs,
          scalacOptions  ++= Seq("-encoding", "UTF-8", "-deprecation", "-unchecked"),
          launchApp)
    )
    

重新部署时记得删除旧~/.<app_name>目录,以便更改生效。

于 2017-06-06T07:35:37.677 回答