IntelliJ not recognizing other SBT project in multi project build
I have an SBT multi project build set up like this:
root -> apps -> contests -> build.sbt
root -> components -> counter -> build.sbt
The root build.sbt has the following contents:
lazy val root =
project.in(file("."))
.aggregate(contests, counter)
.settings(commonSettings: _*)
lazy val contests = project.
in(file("apps/contests")).
dependsOn(counter).
settings(commonSettings: _*)
lazy val counter = project.
in(file("components/counter")).
settings(commonSettings: _*)
When I compile from the command line (sbt contests/compile) everything works fine.
When I go into IntelliJ and try to import the Counter class into a file in the contests app, it can not find the dependency.
even though the dependency shows up in the dependency tree for the contests app:
I feel like I'm missing a setting but I can't figure out what it might be as everything seems to be set up properly from an sbt standpoint because the code compiles.
Please sign in to leave a comment.
Hi, I wasn't able to reproduce the problem from the description alone. Do you think you could create an example project with this issue?
Thanks for the response Justin.
Here is a project that reproduces the issue for me: https://github.com/mikegehard/intellijSbtComponentTroubles
My versions are: IntelliJ (2016.3.1, build 163.9166.29), Scala Plugin (2016.3.5), SBT Plugin (1.8.0).
The steps that I took to open int IntelliJ, in case I missed something:
1. Clone repo.
2. Open IntelliJ
3. File -> New -> Project from existing sources
4. Fill in import box
5. Select defaults for modules
The problematic class is apps/contests/controllers/CountController.scala.
Thanks for your help.
Hi! Sorry I lost track of this.
Counter.scala is in the root directory of the components/counter project, which is not imported as source directory in the IDEA model (you can see this in the Project Structure dialog under "Modules"). If you move the file to src/main/scala, it will be correctly picked up and highlighted by IDEA.You could also manually mark the directory as source dir in Project Structure, but that setting will be lost on the next reimport.
I will have a look if it's a good idea to import the root dir as an additional source dir.
Thanks Justin. I figured it was something small like that.