我有一个build.scala文件,其中的部分看起来像下面的剪辑。 我使用sbt-assembly来构建所有依赖库的jar文件以进行部署。
这很好。我的问题是我跑步'组装'并构建~16MB核心deps文件,然后运行' package'试图构建core.jar文件。它构建core.jar - 但随后它用空文件覆盖我的core-deps.jar文件(因为core-deps没有自己的代码)。
如何构建core.jar和core-deps.jar并且没有' package'吹走core-deps.jar?
lazy val deps = Project("core-deps", file("."),
settings = basicSettings ++
sbtassembly.Plugin.assemblySettings ++
Seq(assemblyOption in assembly ~= { _.copy(includeScala = false) }) ++
addArtifact(Artifact("core-deps", "core-deps"), sbtassembly.Plugin.AssemblyKeys.assembly) ++
Seq(
libraryDependencies ++=
// Master list of all used libraries so it gets added to the deps.jar file when you run assembly
compile(commons_exec, commons_codec, commons_lang, casbah, googleCLHM, joda_time, scalajack, spray_routing, spray_can, spray_client, spray_caching, akka_actor, akka_cluster, akka_slf4j, prettytime, mongo_java, casbah_gridfs, typesafe_config, logback),
jarName in assembly <<= (scalaVersion, version) map { (scalaVersion, version) => "core-deps_" + scalaVersion.dropRight(2) + "-" + version + ".jar" }
)) aggregate(core)
lazy val core = project
.settings(basicSettings: _*)
.settings(buildSettings: _*)
.settings(libraryDependencies ++=
compile(commons_exec, prettytime, commons_codec, casbah, googleCLHM, scalajack, casbah_gridfs, typesafe_config, spray_routing, spray_client, spray_can, spray_caching, akka_actor, akka_slf4j, akka_cluster, logback) ++
test(scalatest, parboiled, spray_client)
)
答案 0 :(得分:2)
为什么不使用sbt-assembly附带的assemblyPackageDependency
任务?请参阅Excluding Scala library, your project, or deps JARs。
如果由于某种原因你真的想在core-deps项目中禁用package
任务,你可以尝试重新布线packageBin
:
packageBin := (outputPath in assembly).value
除了返回文件名之外什么都不做。