jespeno
jespeno

Reputation: 159

sbt multi project undefined settings

I have a multi project setup in SBT. In our build process there's a file in the project that is automatically updated by our CI. It contains the app version.

However, whenever I try to load the app settings, I get an error similar to the following:

[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)

This is what my sbt file looks like:

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"
  )

Here's my version.properties:

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

The interesting thing is, the root project is able to load the settings correctly: if I remove the sub-modules, the build starts correctly. I'm using SBT version 0.13.8.

Upvotes: 2

Views: 668

Answers (1)

chengpohi
chengpohi

Reputation: 14217

This is caused by appProperties not being visible to submodules(module1, module2), you can change it to:

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

sbt scopes

Upvotes: 4

Related Questions