sbt多项目未定义的设置

时间:2016-03-11 02:06:38

标签: scala sbt multi-module

我在SBT中有一个多项目设置。在我们的构建过程中,项目中的文件由我们的CI自动更新。它包含应用程序版本。

但是,每当我尝试加载应用设置时,都会收到类似以下内容的错误:

[error] References to undefined settings: 
[error] 
[error]   module1/*:appProperties from module1/*:version (/Users/jespeno/workspace/multi-module/build.sbt:10)
[error] 
[error]   module2/*:appProperties from module2/*:version (/Users/jespeno/workspace/multi-module/build.sbt:10)

这就是我的sbt文件:

val appProperties = settingKey[Properties]("app version")

appProperties := {
  val prop = new Properties()
  IO.load(prop, new File("version.properties"))
  prop
}

val commonSettings = Seq(
  version := appProperties.value.getProperty("project.version"),
  scalaVersion := "2.11.7"
)

lazy val root = (project in file(".")).settings(commonSettings: _*)
  .aggregate(module1, module2)
  .settings(
    name := appProperties.value.getProperty("project.name")
  )

lazy val module1 = (project in file("./modules/module1"))
  .settings(commonSettings: _*)
  .settings(
    name := "module1"
  )

lazy val module2 = (project in file("./modules/module2"))
  .settings(commonSettings: _*)
  .settings(
    name := "module2"
  )

这是我的version.properties

project.name="multi-module"
project.version="0.0.1"

有趣的是,根项目能够正确加载设置:如果删除子模块,则构建正确启动。我使用的是SBT版0.13.8

1 个答案:

答案 0 :(得分:4)

这是由于appProperties对子模块(module1module2不可见)造成的,您可以将其更改为:

appProperties in Global := {
  val prop = new Properties()
  IO.load(prop, new File("version.properties"))
  prop
}

sbt scopes