2013-05-20 44 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>目錄,以便更改生效。

相關問題