jaksky
jaksky

Reputation: 3405

sbt multi-module project global version setting

I am new to SBT and trying to set up a multi-module project. I come across to a situation where I would like to have a single place where I could have defined versions for libs used accross modules. I tried following with creating a custom settingKey - in the root project:

val akkaVersion = SettingKey[String]("Akka version used in our project")

name := "hello-app"

version in ThisBuild := "1.0.0"

organization in ThisBuild := "com.jaksky.hello"

scalaVersion := "2.10.4"

akkaVersion in ThisBuild:= "2.3.4"

// Common settings/definitions for the build

def OurProject(name: String): Project = (
  Project(name, file(name))
)

lazy val common = (
  OurProject("common")
)

lazy val be_services = (
  OurProject("be-services")
  dependsOn(common)
)

In project be-services I tried following:

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor"   % akkaVersion.value,
  "com.typesafe.akka" %% "akka-cluster" % akkaVersion.value,
  "com.typesafe.akka" %% "akka-kernel"  % akkaVersion.value,
  "com.typesafe.akka" %% "akka-remote"  % akkaVersion.value,
  "com.typesafe.akka" %% "akka-slf4j"   % akkaVersion.value,
  "ch.qos.logback" % "logback-classic"  % "1.0.13"
)

The point here is akkaVersion is not visible (akkaVersion is not found - that is the error message).

My questins:

I found following possibilities:

  1. Scala object holding string constants. Seems to me a bit akward as project version is specified in build.sbt so why dependant libs should be hidden somewhere in project/GlobalVersions.scala or so.
  2. Crating a libDepenDency seq which can be reused. That limits flexibility and I do not always want to be dependant on those libs mentioned.
  3. Custom setting seems to be a bit heavy weighed but seems to me as a claean way but wasn't able to make it work.

Just to complete the picture - using SBT 0.13.5

I believe that this is so fundamental problem that I am not the first one facing this issue.

Thanks for helping me out

Upvotes: 1

Views: 1086

Answers (1)

Renat Bekbolatov
Renat Bekbolatov

Reputation: 329

The definitions in .sbt files are not visible in other .sbt files. In order to share code between .sbt files, define one or more Scala files in the project/ directory of the build root.

[from documentation http://www.scala-sbt.org/]

Upvotes: 2

Related Questions