sbt的assembly插件

1.首先在 project/plugins.sbt: 下加入这段代码:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
2.先对project 执行sbt 看看能不能通过 记住要在机子上装好Git
3.在根目录创建assembly.sbt文件,内容如下:

import AssemblyKeys._ // put this at the top of the file

assemblySettings

// your assembly settings here

之后就可以sbt assembly来打包了,生成./target/scala_x.x.x/projectname-assembly-x.x.x.jar
4.如果想更详细的配置assembly,可以这样

在assembly.sbt内写入:

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)
}
}

你可能感兴趣的:(scala,sbt)