问题描述
我正在使用前面提到的sbt插件来获取我正在使用的应用程序的版本。
I'm using the aforementioned sbt plugin to get the version of the app I'm working on.
该项目有子模块。这是主 build.sbt
The project has sub-modules. Here is the main 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
按预期方式。
The generated BuildInfo.scala
is located under target/scala-2.11/src_managed/main/sbt-buildinfo/BuildInfo.scala
as expected.
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
)
}
}
当我转到包中的文件co.uproot.abandon
并尝试引用 BuildInfo.version
我得到
When I go to a file inside the package co.uproot.abandon
and try to reference BuildInfo.version
I get
Error:(256, 42) object BuildInfo is not a member of package co.uproot.abandon
co.uproot.abandon.BuildInfo.version
我读到了与子模块和此插件并最终尝试解决方法,但没有帮助。
I read about the problem with submodules and this plugin here and ultimately tried this workaround but that didn't help.
任何帮助将不胜感激!
Any help will be appreciated!
推荐答案
问题已解决。
只需确保设置 main
部分 target / scala-2.11 / src_managed /main/sbt-buildinfo/BuildInfo.scala
作为项目结构中的来源用于特定子模块,您希望将其用于不整个项目。
Just make sure to set the main
part of target/scala-2.11/src_managed/main/sbt-buildinfo/BuildInfo.scala
as source in the Project structure for the particular sub-module you would like to use it for and not the whole project.
除此之外,语法高亮显示被搞定,因此它将以与之前相同的方式显示,即不进行编译时。为避免这种情况,请按照我在问题中发布的此中的链接进行操作。
Other than that the syntax highlighting is screwed so it will show up the same way as before i.e. when it wasn't compiling. To avoid that follow the link in this that I posted in the question.
这篇关于无法引用sbt-buildinfo生成的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!