gpt4 book ai didi

sbt - 如何在 sbt 的子模块中继承非托管依赖项?

转载 作者:行者123 更新时间:2023-12-04 20:07:20 25 4
gpt4 key购买 nike

我有一个看起来像这样的项目,使用 sbt 0.13.2:

base
- project
- Build.scala
- plugins.sbt
- lib
- unmanaged jar #1
- unmanaged jar #2
- core
- src
- .......
- clp
- src
- .......
- server
- src
- ......

在哪里 core包含通用代码和 clpserver是两个相关的项目,它们都依赖于 core .

我正在尝试在 Build.scala 中找到合适的魔力这样所有三个模块都依赖于 base/lib .目前我正在使用符号链接(symbolic link)作弊 lib dir 在每个模块中,但我想在没有符号链接(symbolic link)的情况下自动完成。

这是 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
}

最佳答案

这是一个正确的 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
}

关于sbt - 如何在 sbt 的子模块中继承非托管依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23919388/

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