Al-Mothafar
Al-Mothafar

Reputation: 8219

IntelliJ Idea can't resolve symbol that inside Scala managed sources (sbt-buildinfo)

I think it could be a problem that appeared in new versions, and can't be resolved as old versions, I got a Play Java project with sbt-buildinfo plugin the problem is really common is that IntelliJ keep saying it can't resolve that symbol

InjettiJ can't resolve symbol

And here is the file:

Generated file

Some solutions can be found IntelliJ Idea sbt managed source file and here sbt-buildinfo generated object cannot be referenced but none of the solutions provided were helpful for me:

InjelliJ settings

The really strange thing is if I "Unmark the directory as a generated source" and then move that BuildInfo.scala file to the package folder manually to buildpkg (my custom package) instead of sbt-buildinfo package, IntelliJ see that file, but this change is useless because the file will be generated again and all changes will be discarded:

Wow!

Here is my build.sbt:

lazy val root = (project in file(".")).enablePlugins(PlayJava, BuildInfoPlugin)
  .settings(
    buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion, buildInfoBuildNumber,
      "hostname" -> java.net.InetAddress.getLocalHost.getHostName,
      "gitHash" -> sys.env.getOrElse("BITBUCKET_COMMIT", "No BITBUCKET_COMMIT set")
    ),
    buildInfoPackage := "buildpkg",
    buildInfoOptions += BuildInfoOption.ToJson,
    buildInfoOptions += BuildInfoOption.BuildTime
  )

scalaVersion := "2.12.3"

and my plugins.sbt :

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.5")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")

So what I'm missing, what the solution for this

Upvotes: 5

Views: 9446

Answers (2)

Justin Kaeser
Justin Kaeser

Reputation: 5948

  1. In the sbt settings in IntelliJ, enable the settings "Use sbt shell for build and import", since the sources are generated only when sbt runs the build.

  2. IntelliJ will currently only correctly update generated sources if they are in the correct package directory. For sbt-buildinfo, add the setting

    buildInfoUsePackageAsPath := true

    to your build.sbt.

Upvotes: 8

Manabu Tokunaga
Manabu Tokunaga

Reputation: 1094

This issue will also occur if the SBT based project is not "imported" in the first place.

To try to fix this issue:

  1. Close the IntelliJ project in question.
  2. Select Import Project
  3. In the Import Project dialog box, select "Import project from external model"
  4. Select "sbt". Note that "Use sbt shell for build..." is not required to be checked. If you do not click this, you can still take advantage of autoload. Be sure Library sources are checked.

Press Finish and let it build what it needs to now load the plugins and such for the first time.

Upvotes: -2

Related Questions