我有一个看起来像这样的项目,使用sbt 0.13.2:
base
- project
- Build.scala
- plugins.sbt
- lib
- unmanaged jar #1
- unmanaged jar #2
- core
- src
- .......
- clp
- src
- .......
- server
- src
- ......
其中core
包含公共代码,clp
和server
是两个相关项目,均依赖于core
。
我正试图在Build.scala
中找到合适的mojo,以便所有这三个模块都依赖于base/lib
。目前我在每个模块中使用符号链接lib
目录作弊,但我想在没有符号链接的情况下自动执行。
以下是Build.scala
文件的示例 - 如何修改此文件以使依赖项有效?
import sbt._
import Keys._
object RootBuild extends Build {
lazy val buildSettings = Defaults.defaultSettings ++ Seq(
scalaVersion := "2.11.1",
unmanagedBase := baseDirectory.value / "lib"
)
lazy val standardSettings = buildSettings ++ Seq(
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.11" % "2.1.6" % "test",
"org.testng" % "testng" % "6.8.8"
)
)
lazy val Projects = Seq(root, core, clp)
lazy val root = Project("root", file("."), settings=standardSettings) aggregate(core, clp)
lazy val core = Project("core", file("core"), settings=standardSettings)
lazy val clp = Project("clp", file("clp"), settings=standardSettings) dependsOn core
lazy val server = Project("server", file("server"), settings=standardSettings) depensOn core
}
答案 0 :(得分:4)
这是正确的build.sbt
:
lazy val a, b = project settings(
Defaults.defaultSettings ++ Seq(
unmanagedBase := (unmanagedBase in ThisProject).value
): _*
)
我们的想法是根据根项目中的设置值(隐式定义)为子模块设置unmanagedBase
。
在您的特定情况下,它如下:
import sbt._
import Keys._
object RootBuild extends Build {
lazy val buildSettings = Defaults.defaultSettings ++ Seq(
scalaVersion := "2.11.1"
)
lazy val standardSettings = buildSettings ++ Seq(
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.11" % "2.1.6" % "test",
"org.testng" % "testng" % "6.8.8"
)
)
lazy val submoduleSettings = standardSettings ++ Seq(
unmanagedBase := (unmanagedBase in ThisProject).value
)
lazy val root = project in file(".") settings(standardSettings: _*) aggregate(core, clp)
lazy val core = project settings(submoduleSettings: _*)
lazy val clp = project settings(submoduleSettings: _*) dependsOn core
lazy val server = project settings(submoduleSettings: _*) dependsOn core
}