我正在使用前面提到的sbt插件来获取我正在处理的应用程序的版本。
该项目有子模块。这是主build.sbt
...
lazy val abandon = (project in file(".")).
aggregate(base, cli, gui).
dependsOn(base, cli, gui).
enablePlugins(BuildInfoPlugin).
settings(commonSettings: _*).
settings(
name := "abandon",
fork in run := true,
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := "co.uproot.abandon"
)
lazy val base = (project in file("base")).
settings(commonSettings: _*).
settings(
name := "abandon-base",
fork in run := true
)
lazy val cli = (project in file("cli")).
dependsOn(base).
settings(commonSettings: _*).
settings(
name := "abandon-cli",
fork in run := true
)
lazy val gui = (project in file("gui")).
dependsOn(base).
settings(commonSettings: _*).
settings(
name := "abandon-gui",
fork in run := true
)
生成的BuildInfo.scala
按预期位于target/scala-2.11/src_managed/main/sbt-buildinfo/BuildInfo.scala
下。
package co.uproot.abandon
import scala.Predef._
/** This object was generated by sbt-buildinfo. */
case object BuildInfo {
/** The value is "abandon". */
val name: String = "abandon"
/** The value is "0.3.1". */
val version: String = "0.3.1"
/** The value is "2.11.8". */
val scalaVersion: String = "2.11.8"
/** The value is "0.13.12". */
val sbtVersion: String = "0.13.12"
override val toString: String = {
"name: %s, version: %s, scalaVersion: %s, sbtVersion: %s" format (
name, version, scalaVersion, sbtVersion
)
}
}
当我转到package co.uproot.abandon
内的文件并尝试引用BuildInfo.version
时,我得到了
Error:(256, 42) object BuildInfo is not a member of package co.uproot.abandon
co.uproot.abandon.BuildInfo.version
我了解了子模块和此插件here的问题,并最终尝试了this解决方法,但这没有帮助。
任何帮助将不胜感激!
答案 0 :(得分:1)
我想添加一张图片来说明 zaxme
的答案,但我无法在评论中添加,因此我添加了另一个答案以添加有关它的更多信息。
所以,
1 - 右键单击 target/scala-2.11/src_managed/main
:
还有,
2 - 选择 Mark Directory as
和 Unmark Generated Sources Root
:
然后重建,它应该可以工作了。
答案 1 :(得分:0)
问题解决了。
只需确保将main
部分的target/scala-2.11/src_managed/main/sbt-buildinfo/BuildInfo.scala
部分设置为项目结构中的特定子模块,并将其用于不整个项目。
除此之外,语法高亮显示被拧紧,因此它将以与之前相同的方式显示,即不进行编译时。为避免这种情况,请按照我在问题中发布的 this 中的链接进行操作。