sbt的assembly外掛

timger發表於2019-02-16

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

相關文章