Suma Suma - 9 months ago 49
Scala Question

What is the difference between "container" and "provided" in SBT dependencies?

When reading

of many web applications, one can often see dependencies marked as
, see e.g. sbt-assembly documentation:

"org.apache.spark" %% "spark-core" % "0.8.0-incubating" % "provided"

I was unable to find any mention in SBT documentation, however Maven documentation says following about provided:

  • provided

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime

Sometimes however I have also seen
in the same position, like in this build.sbt. Is this the same thing?

val tomcatVersion = "7.0.53"

libraryDependencies ++= Seq(
"org.apache.tomcat.embed" % "tomcat-embed-core" % tomcatVersion % "container",
"org.apache.tomcat.embed" % "tomcat-embed-logging-juli" % tomcatVersion % "container",
"org.apache.tomcat.embed" % "tomcat-embed-jasper" % tomcatVersion % "container",
"org.apache.tomcat" % "tomcat-catalina" % tomcatVersion % "provided",
"org.apache.tomcat" % "tomcat-coyote" % tomcatVersion % "provided"

Answer Source

That forth element of the dependency associates the dependency with a configuration; establishing a configuration dependency. It originates with ivy, which sbt uses internally.

The "container" configuration is defined by xsbt-web-plugin version 0.9, which is brought into the project you reference here. It is being used to establish the container/hosting runtime for sbt container:start.

As an aside - that runtime would necessarily provide the runtime libraries corresponding to the "provided" configuration, which were used during the compile phase but not included in the transitive dependencies for the resulting artifacts.