Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"
)
like image 202
Suma Avatar asked Nov 12 '16 15:11

Suma


People also ask

What is provided dependency in sbt?

The sbt-assembly Plugin In that case, we can mark that dependency as “provided” in our build. sbt file. The “provided” keyword indicates that the dependency is provided by the runtime, so there's no need to include it in the JAR file.

What is provided scope in sbt?

Scoping by the configuration axis Some configurations you'll see in sbt: Compile which defines the main build ( src/main/scala ). Test which defines how to build tests ( src/test/scala ). Runtime which defines the classpath for the run task.

Which is the correct way to add dependencies in sbt file?

Library dependencies can be added in two ways: unmanaged dependencies are jars dropped into the lib directory. managed dependencies are configured in the build definition and downloaded automatically from repositories.

How do we specify library dependencies in sbt?

You can use both managed and unmanaged dependencies in your SBT projects. If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.


1 Answers

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.

like image 148
Richard Sitze Avatar answered Oct 06 '22 19:10

Richard Sitze