sbt-assembly 的发布是针对单个项目的说明,不容易转化为多项目。
人们一直在使用 sbt-assembly 和 sbt-release 发布胖 JAR,没有任何问题。这是 2011 年的一篇博客文章:Publishing fat jar created by sbt-assembly。它归结为添加addArtifact(Artifact(projectName, "assembly"), sbtassembly.AssemblyKeys.assembly)
到您的build.sbt
(请注意,该博客有点过时,AssemblyKeys
现在是sbtassembly
直接成员)。
对于 sbt 0.13 及更高版本,我也更喜欢build.sbt
用于多项目,所以我会这样写:
import AssemblyKeys._
lazy val commonSettings = Seq(
version := "0.1-SNAPSHOT",
organization := "com.example",
scalaVersion := "2.10.1"
)
val app = (project in file("app")).
settings(commonSettings: _*).
settings(assemblySettings: _*).
settings(
artifact in (Compile, assembly) ~= { art =>
art.copy(`classifier` = Some("assembly"))
}
).
settings(addArtifact(artifact in (Compile, assembly), assembly).settings: _*)
请参阅定义自定义工件:
addArtifact 返回一系列设置(包装在 SettingsDefinition 中)。在完整的构建配置中,用法如下所示:
...
lazy val proj = Project(...)
.settings( addArtifact(...).settings : _* )
...