2013-05-20 46 views
1

我正在开发an sbt launched application与定制command line interface。 问题是,每次我想测试它时,我必须删除先前发布的boot目录,然后重新编译并在本地发布这些工件,然后运行该应用程序并手动对其进行测试。部分工作是通过运行外部shell脚本完成的。是否可以从sbt重新启动并测试xsbti.AppMain衍生应用程序?

我该如何让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 
    } 

回答

0
  1. 创建launcher configuration文件,例如fqb.build.properties在项目的主目录中。

  2. 创建启动应用程序

    #!/usr/bin/env bash 
    
    java -jar /path/to/sbt-launch.jar "[email protected]" 
    
  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>目录,以便更改生效。

相关问题