简体   繁体   中英

sbt-buildinfo generated object cannot be referenced

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!

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 ie when it wasn't compiling. To avoid that follow the link in this that I posted in the question.

I wanted to add an image to illustrate zaxme answer, but I can't in the comments, so I am adding another answer to add more information about it.


So,

1 - Right click on target/scala-2.11/src_managed/main :

在此处输入图片说明


And,

2 - Select Mark Directory as and Unmark Generated Sources Root :

在此处输入图片说明


Then rebuild, it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM