sbt-assembly icon indicating copy to clipboard operation
sbt-assembly copied to clipboard

Optional dependencies are automatically included

Open connesc opened this issue 8 years ago • 2 comments
trafficstars

When a library declares optional dependencies, they are automatically included in the resulting fat JAR. I guess this is not the expected behavior.

A good example is elasticsearch-spark-20 (elasticsearch-spark-20_2.11-5.5.2.pom), which declares some Spark dependencies: the provided one is properly ignored, but the optional ones are not.

For now, a possible workaround is to explicitly exclude them:

"org.elasticsearch" %% "elasticsearch-spark-20" % "5.5.2" excludeAll ExclusionRule(organization = "org.apache.spark")

connesc avatar Aug 31 '17 16:08 connesc

was there any progress since 2017? I think from a security point of view it is always a good idea of using as less dependencies as possible. Which means optional dependencies should be excluded by default.

bes1002t avatar Dec 13 '21 12:12 bes1002t

Could someone check if this still happens with the latest sbt 1.5.6?

In general sbt-assembly grabs whatever in the runtime classpath of sbt, so if there's a problem the the resolved JARs it's a problem with sbt and specifically in this case an issue with dependency management engine like Coursier or Apache Ivy.

eed3si9n avatar Dec 13 '21 20:12 eed3si9n