添加托管库依赖项
libraryDependency
是处理’托管’库依赖项的 SettingKey
,它是自动下载的依赖项,与提供的版本匹配。要添加单个依赖项:
libraryDependencies += "com.typesafe.slick" %% "slick" % "3.2.0-M1"
第一部分 com.typesafe.slick
表示库包。第二部分 slick
是有问题的库。最后一部分 3.2.0-M1
是版本。由于库由%%
连接,因此将使用 scalaVersion
设置键提供的 Scala 版本。
你可以使用++=
一次添加多个库:
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"
)
记住 Scala 的功能特性,允许你计算依赖关系。记住要回归一个 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
}