Chris Mantle
Chris Mantle

Reputation: 6693

Adding just specific dependencies to an SBT-packaged jar file

I'm writing a small Scala library. My library is dependent on two others - let's call them A and B. I would like to include A in my assembly's jar file, but not B, because 1) client code will always have a dependency on B, so it will always be present, and 2) B is a very large assembly.

Building with sbt assembly creates a fat jar with all dependencies. Building with sbt package creates a skinny jar with just my library's classes in it and nothing more. I'd like some kind of semi-skimmed jar that contains my classes and just the jar of dependency A.

I have had a look for potential modifications or additions to my Build.scala file to have SBT include just a specific dependency when it builds a jar, but I haven't managed to find anything to do. I'm not certain it's possible. Any help or guidance would be much appreciated.

Upvotes: 3

Views: 1363

Answers (1)

gourlaysama
gourlaysama

Reputation: 11290

If you are sure the B dependency will always be present at runtime, you can always mark B as provided.

libraryDependencies += "com.youcompany" %% "b-library" % "1.0" % "provided"

This means it will be included in the compile dependencies, but will be provided some other way at runtime, so there is no need to package it.

Upvotes: 3

Related Questions