如何在 sbt 的子模块中继承非托管依赖项? [英] How to inherit unmanaged dependencies in submodules in sbt?
问题描述
我有一个看起来像这样的项目,使用 sbt 0.13.2:
I have a project which looks like this, using 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
.
where core
contains common code and clp
and server
are two related projects which both depend on core
.
我正在尝试在 Build.scala
中找到正确的 mojo,以便所有这三个模块都依赖于 base/lib
.目前我通过在每个模块中使用符号链接的 lib
目录来作弊,但我想在没有符号链接的情况下自动进行.
I'm trying to find the right mojo in Build.scala
such that all three of these modules depend on base/lib
. Currently I'm cheating by using a symlink'd lib
dir in each of the modules, but I'd like to do it automatically without the symlinks.
这是 Build.scala
文件的示例 - 我应该如何修改它以使依赖项工作?
Here's an example of Build.scala
file - how should I modify this to make the dependencies work?
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
}
推荐答案
这是一个正确的build.sbt
:
lazy val a, b = project settings(
Defaults.defaultSettings ++ Seq(
unmanagedBase := (unmanagedBase in ThisProject).value
): _*
)
想法是根据根项目中设置的值(隐式定义)为子模块设置 unmanagedBase
.
The idea is to set unmanagedBase
for the submodules based upon the value of the setting in the root project (that's defined implicitly).
在您的特定情况下,如下所示:
In your particular case it'd be as follows:
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
}
这篇关于如何在 sbt 的子模块中继承非托管依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!