与此question有些相似,如何在子项目中引用自定义设置。
在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"))
在thrift / build.sbt中:
name := "thrift"
// doesn't work
libraryDependencies ++= Seq(
"com.twitter" %% "finagle-thriftmux" % (finagleVersion in LocalRootProject).value
)
答案 0 :(得分:9)
.sbt
个文件无法查看其他val
文件中的定义(例如.sbt
s),即使它们属于同一版本。
但是,构建中的所有.sbt
个文件都可以查看/导入project/*.scala
个文件的内容。因此,您必须在val finagleVersion
文件中声明.scala
:
project/CustomKeys.scala
:
import sbt._
import Keys._
object CustomKeys {
val finagleVersion = settingKey[String]("Defines the Finagle version")
}
现在,在您的.sbt
文件中,只需
import CustomKeys._
你很高兴。