sbt Dependencies Add a Managed Library Dependency

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

libraryDependency is the SettingKey that handles 'managed' library dependencies, which are dependencies that are automatically downloaded, matching the supplied versions. To add a single dependency:

libraryDependencies += "com.typesafe.slick" %% "slick" % "3.2.0-M1"

The first part, "com.typesafe.slick", indicates the library package. The second part, "slick", is the library in question. The final part, "3.2.0-M1", is the version. Because the library is joined by %% the version of Scala supplied by the scalaVersion setting key will be utilized.

You can add multiple libraries at once using ++=:

libraryDependencies ++= Seq(
  "com.typesafe.slick" %% "slick" % "3.2.0-M1" % "compile",
  "com.typesafe.slick" %% "slick-hikaricp" % "3.2.0-M1",
  "mysql" % "mysql-connector-java" % "latest.release"
)

Remember Scala's functional nature, allowing you to compute dependencies. Just remember to return a Seq:

libraryDependencies ++= {
  lazy val liftVersion = "3.0-RC3" //Version of a library being used
  lazy val liftEdition = liftVersion.substring(0,3) //Compute a value
  Seq(
    "net.liftweb" %% "lift-webkit" % liftVersion % "compile",  // Use var in Seq
    "net.liftmodules" %% ("ng_" + liftEdition) % "0.9.2" % "compile",  // Use computed var in Seq
  )  // Because this is the last statement, the Seq is returned and appended to libraryDependencies
}


Got any sbt Question?