sbt-buildinfo generated object cannot be referenced

纵然是瞬间 提交于 2019-12-24 09:48:09

问题


I'm using the aforementioned sbt plugin to get the version of the app I'm working on.

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
  )

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
    )
  }
}

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!


回答1:


Issue solved.

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.



来源:https://stackoverflow.com/questions/40227891/sbt-buildinfo-generated-object-cannot-be-referenced

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!