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.
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.
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).
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With