Working on multiple interdependent SBT projects with IntelliJ

Viewed 549

I'm working on a library and an app which depends on it in parallel, and I'd like to publish them separately. Since I frequently edit both, I'd like to be able to load both of them in IntelliJ such that "Go to definition" works correctly (i.e. takes me to the editable source of the other project), and rebuilding will incorporate changes made in the other module without having to rerun sbt publishLocal and refresh the other project.

I managed to get IntelliJ to do this by manually adding multiple SBT projects and editing their dependencies by hand, but my edits disappeared as soon as I added a library dependency and refreshed the SBT definitions.

How can I get IntelliJ to understand that a libraryDependency on the other project should be realised and imported as a module, rather than from the local maven repository?

1 Answers

I'm also looking for a solution to your question. However, up till then I can hopefully offer an acceptable workaround.

You could temporarily remove your Ivy2 dependency from your project and define it instead as a project in your sbt. For example if your OtherProject is in the same Directory as your current project, then you can add it as follows:

lazy val otherProject = RootProject(file("../OtherProject")) 

Afterwards, you need to specify a dependency to OtherProject using dependsOn:

lazy val myProjectRoot = project.in(file(".")).settings(...).dependsOn(otherProject)

IntelliJ then imports the OtherProject into the current Workspace and you can work on both.

Before you commit, you have to revert the dependency to the Ivy2 specification.

Related