Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between adding a dependency via libraryDependencies versus an sbt plugin?

Tags:

scala

sbt

I am a Scala newbie trying to understand the nuances of the language and tooling. I'm looking through a sample at https://github.com/swagger-api/swagger-samples/tree/master/scala/scala-play2.4 that uses play and I notice that the play dependency is added like so:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6")
https://github.com/swagger-api/swagger-samples/blob/master/scala/scala-play2.4/project/plugins.sbt

However in various other SO posts I see the dependency being added to libraryDependencies like so:

libraryDependencies ++= Seq("com.typesafe.play" %% "play" % "2.2.2")
https://stackoverflow.com/a/22215070/201657

or

libraryDependencies += "com.typesafe.play" %% "play-json" % "2.3.4"
https://stackoverflow.com/a/19438083/201657

What is the difference, and what are the implications, of these two techniques of adding a dependency? TIA.

like image 409
jamiet Avatar asked Mar 15 '19 09:03

jamiet


People also ask

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.

What is a sbt plugin?

A plugin can define a sequence of sbt settings that are automatically added to all projects or that are explicitly declared for selected projects. For example, a plugin might add a proguard task and associated (overridable) settings. Finally, a plugin can define new commands (via the commands setting).

What is sbt dependency management?

Like in almost every build system, SBT allows you to define library dependencies which are resolved automatically, so you don't have to download and package required libraries by yourself.


1 Answers

As mentioned in linked SO answer, sbt-plugins are used to enhance build behaviour.

In case of addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6") the pluging is modifying your build's libraryDependencies by following code. Thus the dependency management is done by the plugin.

If you choose to manage it yourself, you could use following without enabling the com.typesafe.play" % "sbt-plugin.

libraryDependencies ++= Seq("com.typesafe.play" %% "play" % "2.4.6")

If you choose to use sbt to launch your play application with hot reload functionality, you should consider using the sbt-plugin. But if you don't care about it, just add play as libraryDependencies.

like image 144
Ivan Stanislavciuc Avatar answered Sep 22 '22 13:09

Ivan Stanislavciuc