Greg
Greg

Reputation: 11542

How to exclude assembly from package in sbt?

I have a build.scala file that has a section that looks something like the clip below. I use sbt-assembly to build a jar file of all dependent libs for deployment.

This builds fine. My problem is that I run 'assembly' and that builds ~16MB core-deps file, then I run 'package' trying to build the core.jar file. It builds core.jar--but then it overwrites my core-deps.jar file with an empty file (because core-deps has no code of its own).

How can I build both core.jar and core-deps.jar and not have 'package' blow away 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)
    )

Upvotes: 0

Views: 2013

Answers (1)

Eugene Yokota
Eugene Yokota

Reputation: 95684

Why not use assemblyPackageDependency task that comes with sbt-assembly? See Excluding Scala library, your project, or deps JARs.

If for some reason you really want to disable package task in core-deps project, you could try rewiring the packageBin:

packageBin := (outputPath in assembly).value

That will do nothing but return the file name.

Upvotes: 2

Related Questions