How to reference SBT Customizing in subprojects

To some extent similar to this question , how can a user parameter be referenced in a subproject.

In build.sbt:

import sbt.Keys._ val finagleVersion = settingKey[String]("Defines the Finagle version") val defaultSettings = Defaults.coreDefaultSettings ++ Seq( finagleVersion in ThisBuild := "6.20.0", organization in ThisBuild := "my.package", scalaVersion in ThisBuild := "2.10.4", version in ThisBuild := "0.1-SNAPSHOT" ) lazy val root = project.in(file(".")).aggregate(thrift).settings( publishArtifact in (Compile, packageBin) := false, publishArtifact in (Compile, packageDoc) := false, publishArtifact in (Compile, packageSrc) := false ) lazy val thrift = project.in(file("thrift")) 

In transaction /build.sbt:

 name := "thrift" // doesn't work libraryDependencies ++= Seq( "com.twitter" %% "finagle-thriftmux" % (finagleVersion in LocalRootProject).value ) 
+5
source share
1 answer

.sbt files cannot see definitions (e.g. val s) in other .sbt files, even if they are part of the same assembly.

However, all .sbt files in the assembly can see / import the contents of the project/*.scala .sbt files. So you need to declare your val finagleVersion in a .scala file:

project/CustomKeys.scala :

 import sbt._ import Keys._ object CustomKeys { val finagleVersion = settingKey[String]("Defines the Finagle version") } 

Now, in your .sbt files, just

 import CustomKeys._ 

and you are good to go.

+8
source

Source: https://habr.com/ru/post/1203845/


All Articles