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

1

7

When reading build.sbt of many web applications, one can often see dependencies marked as "provided", 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 "container" 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"
)
Fetiparous answered 12/11, 2016 at 15:35 Comment(0)
P
4

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.

Phocaea answered 12/11, 2016 at 20:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.