2012-11-20 34 views
1

我正在考慮使用thrift作爲使用播放框架編寫的服務器的傳輸。 Thrift必須將IDL文件轉換爲java源文件。使用典型的構建過程(例如ant),我知道如何在進入主編譯步驟之前創建生成的源。由於Play控制了編譯過程,我不確定如何將生成的源注入構建過程,或者即使可能。有沒有辦法爲Play創建額外的構建步驟,還是隻需要確保手動更新我的thrift文件?在播放框架(特別是節儉)中生成的源

回答

0

播放2採用SBT作爲構建工具,所以你可以使用完整的SBT功率: http://www.scala-sbt.org/release/docs/Howto/generatefiles.html

添加在Build.scala在設置()塊的源發生器:

val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
    sourceGenerators in Compile <+= sourceManaged in Compile map { dir => 
    //example for one scala file, call your thrift generation here for multiple files 
    val file = dir/"demo"/"Test.scala" 
    IO.write(file, """object Test extends App { println("Hi") }""") 

    Seq(file) //list your generated files here 
    } 
)