2016-11-19 46 views
0

我有一個scala項目,我已經導入了sbt彙編和本地打包器插件。集成sbt DIST和彙編命令

現在我可以做sbt assembly它爲我的項目構建了一個胖罐子。

我的願望是,如果我做sbt dist那麼這個胖jar就是打包成一個本地格式,如zip文件。但是,當我爲我的項目執行sbt dist時,它只是生成一個包含所有jar文件的zip文件。它不接我的胖罐子。

我之所以想胖罐子是,sbt dist是一味的包裝都沒有任何合併策略,因此輸出失敗的錯誤。我的fat jar工作正常,因爲我在build.sbt中編寫了合併策略。

但我無法用dist命令打包我的胖罐子。

回答

0

找到了答案。將以下內容添加到build.sbt項目設置中

// add this on top of file 
import com.typesafe.sbt.SbtNativePackager._ 

// add this to project settings 
mappings in Universal := { 
    // universalMappings: Seq[(File,String)] 
    val universalMappings = (mappings in Universal).value 
    val fatJar = (assembly in Compile).value 

    // removing means filtering 
    // notice the "!" - it means NOT, so only keep those that do NOT have a name ending with "jar" 
    val filtered = universalMappings filter { 
    case (file, name) => ! name.endsWith(".jar") 
    } 

    // add the fat jar to our sequence of things that we've filtered 
    filtered :+ (fatJar -> ("lib/" + fatJar.getName))