4

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!

Community
  • 1
  • 1
zaxme
  • 1,065
  • 11
  • 29
  • I have a project with a *very* similar setup, and I'm not having a problem. After configuring it as you have here, have you tried `Invalidate Caches/Restart` in your IntelliJ 'File' menu? What version of IntelliJ/SBT/Scala etc. are you using? – Nathaniel Ford Oct 25 '16 at 00:55
  • @NathanielFord I just did that per your suggestion and it didn't help. For reference I use: IntelliJ - **2016.2.5** SBT - **0.13.12** Scala - **2.11.6** – zaxme Oct 25 '16 at 07:04

2 Answers2

4

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:

enter image description here


And,

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

enter image description here


Then rebuild, it should work.

Axel Borja
  • 3,718
  • 7
  • 36
  • 50
3

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.

zaxme
  • 1,065
  • 11
  • 29
  • 2
    Ah! Glad you found an answer: it would have been clear if you had indicated which project you'd been referencing from (I had assumed root based on the package). You should add a working config to your answer for future folks! – Nathaniel Ford Oct 25 '16 at 17:27
  • 1
    Thanks +1. Moreover, I just added an answer with screenshots to illustrate a little bit more. – Axel Borja Jan 08 '21 at 16:17