4
votes

I've just installed SBT plugin for IntelliJ and successfully imported my project. SBT console in IntelliJ shows up as expected, however I can't use it because of layout of my project. The entire problem is that my SBT Play! project is not a top-level directory. Instead I have maven parent pom with several child modules amongst which my SBT application is placed. This is how it looks like:

MyProject (parent pom)
-> submodule1 (JAR)
-> submodule2 (JAR)
-> webapp (SBT Play! webapp module)

There is no problem to run Play! application from Linux CLI, previously changing directory to MyProject\webapp and executing SBT from there. However, I don't see any option to set root dir for SBT console in IntelliJ. I have entire project imported into workspace, so the default project root directory is MyProject which is obviously not treaded as SBT project.

Is there any way to change "working directory" for IntelliJ SBT plugin?

1

1 Answers

3
votes

I had the same issue, here's how I got it going:

  1. Start by adding your root as a new module. In your case it will MyProject. I was careful to add this as a blank module, but if you already have something like a pom file (which begs the question as to why you want to use SBT), then you might be okay letting IntelliJ import it for you.
  2. Next, add a scala file to your root project directory to map the sub-projects. A great explanation on how to set one of these up can be found on the scala wiki

import sbt._ import Keys._

object HelloBuild extends Build {
    lazy val root = Project(id = "MyProject",
                            base = file(".")) aggregate(submodule1, submodule2, webapp)    

lazy val submodule1 = Project(id = "submodule1",
                           base = file("submodule1"))

    lazy val submodule2 = Project(id = "submodule2",
                           base = file("submodule2"))

    lazy val webapp = Project(id = "webapp",
                           base = file("webapp"))

}
  1. Start your SBT and you should now be able to switch between projects. If you have it up and running, make sure you use the reload command to apply the changes.

You can list the projects SBT recognizes as modules with the projects command. Switch projects by using project [projectName]. So to switch to submodule2, just type project submodule2.