我使用 sbt 0.13.3-SNAPSHOT:
[sbt-0-13-3]> about
[info] This is sbt 0.13.3-SNAPSHOT
[info] The current project is {file:/Users/jacek/sandbox/so/sbt-0.13.3/}sbt-0-13-3 1.0-build_sbt
[info] The current project is built against Scala 2.11.0-RC3
[info] Available Plugins: sbt.plugins.IvyModule, sbt.plugins.JvmModule, sbt.plugins.GlobalModule, com.typesafe.sbt.SbtGit, com.typesafe.sbt.SbtProguard, growl.GrowlingTests, org.sbtidea.SbtIdeaPlugin, sbtman.Plugin, np.Plugin, com.timushev.sbt.updates.UpdatesPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.3
tl;dr(version in ThisBuild).value
当您需要配置中version
设置的值时使用ThisBuild
。
给定以下version.sbt文件:
version in ThisBuild := "1.0-version_sbt"
和以下build.sbt(注(version in ThisBuild).value
):
scalaVersion := "2.11.0-RC3"
version := "1.0-build_sbt"
artifactName := {
(sv: ScalaVersion, module: ModuleID, artifact: Artifact) => {
val suffix = "-" + sys.props.getOrElse("environment","dev") + (if (artifact.classifier.isDefined) "-" + artifact.classifier.get else "")
artifact.name + "_" + sv.binary + "-" + (version in ThisBuild).value + suffix + "." + artifact.extension
}
}
sbt shell 给了我以下输出:
[sbt-0-13-3]> show makePom::artifactPath
[info] /Users/jacek/sandbox/so/sbt-0.13.3/target/scala-2.11.0-RC3/sbt-0-13-3_2.11.0-RC3-1.0-version_sbt-dev.pom
我使用makePom::artifactPath
了设置,因为我注意到它是一个反向依赖artifactName
(否则我将无法显示artifactName
函数的值):
[sbt-0-13-3]> inspect artifactName
[info] Setting: scala.Function3[sbt.ScalaVersion, sbt.ModuleID, sbt.Artifact, java.lang.String] = <function3>
[info] Description:
[info] Function that produces the artifact name from its definition.
[info] Provided by:
[info] {file:/Users/jacek/sandbox/so/sbt-0.13.3/}sbt-0-13-3/*:artifactName
[info] Defined at:
[info] /Users/jacek/sandbox/so/sbt-0.13.3/build.sbt:5
[info] Dependencies:
[info] {.}/*:version
[info] Reverse dependencies:
[info] *:makePom::artifactPath
[info] Delegates:
[info] *:artifactName
[info] {.}/*:artifactName
[info] */*:artifactName
[info] Related:
[info] */*:artifactName
至于您想为您设置 Play 项目的版本的情况,version in ThisBuild
您不必担心它,因为 sbt 会为您执行此操作。
val appVersion := ... // some operation on version in ThisBuild
val main = play.Project(appName, appVersion, dependencies = appDependencies)
做什么play.Project
(参见GitHub 上的 play.Project.scala)是传递applicationVersion
给version
并且因为您在version.sbt
其中设置的版本已经由 sbt 本身设置。但是,如果您想明确执行此操作,请执行以下操作:
version := (version in ThisBuild).value
在build.sbt
.
[sbt-0-13-3]> show version
[info] 1.0-build_sbt
[sbt-0-13-3]> reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/so/sbt-0.13.3/project
[info] Set current project to sbt-0-13-3 (in build file:/Users/jacek/sandbox/so/sbt-0.13.3/)
[sbt-0-13-3]> show version
[info] 1.0-version_sbt