简体   繁体   中英

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:

  • Is settings map shared accross modules? Described issue probably answers -> NO
  • What is best practice in this situation?

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

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/]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM