Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 564
Al-Mothafar Avatar asked Oct 16 '17 05:10

Al-Mothafar


1 Answers

  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.

like image 165
Justin Kaeser Avatar answered Oct 06 '22 00:10

Justin Kaeser