我在这里使用sbt .13。
到目前为止,我有这个:
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appVersion = "1.0"
resolvers += "local maven" at "/Users/blankman/.m2/repository/"
val commonDependencies = Seq()
val modelDependencies = Seq(
"com.typesafe.slick" %% "slick" % "2.0.1",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
val serviceDependencies = Seq(
"com.typesafe.slick" %% "slick" % "2.0.1",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
val webDependencies = Seq(
//"org.apache.tomcat" % "tomcat-jdbc" % "8.0.3",
"mysql" % "mysql-connector-java" % "5.1.30",
"com.typesafe.slick" %% "slick" % "2.0.1"
)
lazy val common = Project(
id = "app-common",
base = file("app-common"),
dependencies = commonDependencies
)
lazy val models = Project(
id = "app-models",
base = file("app-models"),
settings(modelDependencies: _*)
)
).dependsOn(common)
lazy val services = Project(
id = "app-services",
base = file("app-services"),
settings = Seq(
libraryDependencies ++= serviceDependencies
)
).dependsOn(models, common)
lazy val web = play.Project("app-web", appVersion, webDependencies,
path = file("app-web"))
.settings(playScalaSettings: _*)
.dependsOn(services)
}
这不起作用,例如,如果我进入:
项目应用模型
并尝试编译,它说编译无效或其他。
我真的很困惑如何设置项目,正确的方法是什么?
在此处查看此幻灯片#10 http://jsuereth.com/scala/2013/06/11/effective-sbt.html它说我能做到:
lazy val web = (
Project("app-models", file("app-models"))
settings(
libraryDependencies += modelDependencies
)
)
但是当我这样做时,我也会收到错误。
我基本上在sbt中有一些项目:
common
models
services
web (which is play)
有人可以帮我解决这个问题吗?
答案 0 :(得分:46)
我在构建定义中发现了一些问题,但是既然你买了Josh的Effective sbt谈话,我认为我们应该全力以赴。
以下是文件。
sbt.version=0.13.2
val playVersion = "2.2.2"
resolvers += Resolver.typesafeRepo("releases")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % playVersion)
import sbt._
import Keys._
object Commons {
val appVersion = "1.0"
val settings: Seq[Def.Setting[_]] = Seq(
version := appVersion,
resolvers += Opts.resolver.mavenLocalFile
)
}
import sbt._
import Keys._
object Dependencies {
val slickVersion = "2.0.1"
val slick = "com.typesafe.slick" %% "slick" % slickVersion
val slf4jVersion = "1.6.4"
val slf4jNop = "org.slf4j" % "slf4j-nop" % slf4jVersion
val mysqlConnectorVersion = "5.1.30"
val mysqlConnector = "mysql" % "mysql-connector-java" % mysqlConnectorVersion
val commonDependencies: Seq[ModuleID] = Seq(
slick,
slf4jNop
)
val modelDependencies: Seq[ModuleID] = Seq()
val serviceDependencies: Seq[ModuleID] = Seq()
val webDependencies: Seq[ModuleID] = Seq(
mysqlConnector
)
}
import play.Project._
import Dependencies._
lazy val appCommon = (project in file("app-common")).
settings(Commons.settings: _*).
settings(
libraryDependencies ++= commonDependencies
)
lazy val appModels = (project in file("app-models")).
settings(Commons.settings: _*).
settings(
libraryDependencies ++= modelDependencies
).
dependsOn(appCommon)
lazy val appServices = (project in file("app-services")).
settings(Commons.settings: _*).
settings(
libraryDependencies ++= serviceDependencies
).
dependsOn(appModels, appCommon)
lazy val appWeb = (project in file("app-web")).
settings(Commons.settings: _*).
settings(playScalaSettings: _*).
dependsOn(appServices)
对于models
和services
,您将设置序列传递到Project(...)
构造函数,因此可能未加载默认设置。您可以手动传递默认设置,也可以在settings(...)
上使用Project
方法,我建议这样做。
lazy val appModels = (project in file("app-models")).
settings(
libraryDependencies ++= modelDependencies
).
dependsOn(appCommon)
Josh使用括号使用后缀表示法,但我更喜欢使用点表示法,因此与谈话略有偏差。
如上例所示,您必须将modelDependencies
传递给libraryDependencies
。你让它直接调用settings
。
resolvers
设置不会传递给任何可能不正确的内容。