7

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.

jamiet
  • 10,501
  • 14
  • 80
  • 159
  • 3
    You should probably gain some understanding from this https://stackoverflow.com/questions/33771269/what-is-the-difference-between-plugins-dependencies-modules-and-sub-projects-i Broadly, plugins enhance sbt's functionality and dependencies are what you use in your project to write code. – debduttoc Mar 15 '19 at 11:00

1 Answers1

4

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.

Ivan Stanislavciuc
  • 7,140
  • 15
  • 18