gpt4 book ai didi

scala - 困惑如何建立多项目 sbt 项目

转载 作者:行者123 更新时间:2023-12-02 19:28:23 25 4
gpt4 key购买 nike

我在这里使用 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)
  • 模型取决于公共(public)资源
  • 服务取决于公共(public)资源+模型
  • 网络依赖于服务

有人可以帮我让它发挥作用吗?

最佳答案

我在您的构建定义中发现了一些问题,但自从您购买了 Josh 的 Effective sbt说吧,我认为我们应该全力以赴地追求风格。

有效的sbt

这是文件。

项目/build.properties

sbt.version=0.13.2

项目/play.sbt

val playVersion = "2.2.2"

resolvers += Resolver.typesafeRepo("releases")

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % playVersion)

项目/commons.scala

import sbt._
import Keys._

object Commons {
val appVersion = "1.0"

val settings: Seq[Def.Setting[_]] = Seq(
version := appVersion,
resolvers += Opts.resolver.mavenLocalFile
)
}

项目/依赖项.scala

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
)
}

构建.sbt

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)

注释

设置参数与设置方法

对于 modelsservices,您将设置序列传递到 Project(...) 构造函数中,因此默认设置为可能未加载。您可以手动传入默认设置,或者在 Project 上使用 settings(...) 方法,我推荐这样做。

lazy val appModels = (project in file("app-models")).
settings(
libraryDependencies ++= modelDependencies
).
dependsOn(appCommon)

Josh 使用带括号的后缀表示法,但我更喜欢使用点表示法,因此这与演讲略有偏差。

库依赖++=

如上面的示例,您必须将 modelDependency 传递给 libraryDependency。您已将其直接调用设置

解析器

resolvers 设置未传递到任何内容,这可能不正确。

关于scala - 困惑如何建立多项目 sbt 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23188771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com