Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding just specific dependencies to an SBT-packaged jar file

Tags:

scala

sbt

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.

like image 485
Chris Mantle Avatar asked Nov 29 '25 17:11

Chris Mantle


1 Answers

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.

like image 131
gourlaysama Avatar answered Dec 01 '25 09:12

gourlaysama