gpt4 book ai didi

scala - 将 build.sbt 与 project/Build.scala 和聚合混合

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

在我有这样的东西(简化)之前,使用 sbt 0.11.3:

// project/Build.scala
import sbt._
import Keys._

object MyBuild extends Build {
lazy val standardSettings = Defaults.defaultSettings ++ Seq(
version := "0.2",
scalaVersion := "2.9.2"
)

lazy val main = Project(
id = "main",
base = file( "." ),
settings = standardSettings,
aggregate = Seq( sub )
)

lazy val sub = Project(
id = "main-sub",
base = file( "sub" ),
settings = standardSettings
)
}

但我想在平原中保留尽可能多的信息 build.sbt文件。所以现在我有
// build.sbt
version := "0.2"

scalaVersion := "2.9.2"


// project/Build.scala
import sbt._
import Keys._

object MyBuild extends Build {
lazy val main = Project(
id = "main",
base = file( "." ),
aggregate = Seq( sub )
)

lazy val sub = Project(
id = "main-sub",
base = file( "sub" )
)
}

但这似乎并没有混入我来自 build.sbt 的设置中进入子项目:
> show version
[info] main-sub/*:version
[info] 0.1-SNAPSHOT
[info] main/*:version
[info] 0.2
> show scala-version
[info] main-sub/*:scala-version
[info] 2.9.1
[info] main/*:scala-version
[info] 2.9.2

如何补救?我还尝试添加明确的 settings到子项目,例如
  • settings = Defaults.defaultSettings
  • settings = Project.defaultSettings
  • settings = MyBuild.settings
  • settings = main.settings (确定这个应该做?!)

  • ...但没有一个工作。

    最佳答案

    信息在sbt's Multi Projects documentation的最后一段有点隐藏:

    When having a single .scala file setting up the different projects, it's easy to use reuse settings across different projects. But even when using different build.sbt files, it's still easy to share settings across all projects from the main build, by using the ThisBuild scope to make a setting apply globally.



    因此:
    // build.sbt
    version in ThisBuild := "0.2"

    scalaVersion in ThisBuild := "2.9.2"

    哇,如果你有两打 key ,那真是太糟糕了。

    关于scala - 将 build.sbt 与 project/Build.scala 和聚合混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11694045/

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