sbt-assembly 发布 Scala 项目

来源:互联网 发布:it helpdesk面试题 编辑:程序博客网 时间:2024/04/28 20:47

sbt-assembly 是一个非常实用的sbt插件,可以将当前项目的二进制包以及依赖的所有第三方库都打包成一个jar包发布,即one-jar, 对于那种直接运行的应用程序很方便。
1.首先在 project/plugins.sbt: 下加入这段代码:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")

2、手工建立 ./assembly.sbt(注意:文件放在根目录下,主要作用是对assembly进行设置):

import AssemblyKeys._ // put this at the top of the fileassemblySettings// your assembly settings here

3、运行assembly任务,生成./target/scala_x.x.x/projectname-assembly-x.x.x.jar:

   assembly

一个可参考的assembly配置:

 import AssemblyKeys._ assemblySettings jarName in assembly := "spark_sbt.jar" test in assembly := {} mainClass in assembly := Some( "Spark_Test") assemblyOption in packageDependency ~= { _.copy(appendContentHash = true) }mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>{  case PathList(ps @ _*) if ps.last endsWith "axiom.xml" => MergeStrategy.filterDistinctLines  case PathList(ps @ _*) if ps.last endsWith "Log.class" => MergeStrategy.first  case PathList(ps @ _*) if ps.last endsWith "LogConfigurationException.class" => MergeStrategy.first  case PathList(ps @ _*) if ps.last endsWith "LogFactory.class" => MergeStrategy.first  case PathList(ps @ _*) if ps.last endsWith "SimpleLog$1.class" => MergeStrategy.first  case x => old(x)}}

https://github.com/sbt/sbt-assembly

0 0
原创粉丝点击