sbt-idea-plugin: dependsOn(RootProject(...)) crashes on IntelliJ import and excludes external projects from packaging
Problem
When an IntelliJ plugin project uses dependsOn(RootProject(...)) to depend on a normal SBT project, two errors occur during IntelliJ import:
NoSuchElementException in topoSortRefs — projectMap(root) crashes when the root is an external ProjectRef not in the map
RuntimeUndefined for intellijExtraRuntimePluginsInTests — settings aggregation via ScopeFilter(inDependencies(ThisProject)) reaches external projects that don't have sbt-idea-plugin enabled
Additionally, even after working around the crashes, external projects are excluded from the packaging graph — their class files and library dependencies are never included in the plugin artifact. This forces users to:
- Use
packageFileMappings with explicit JARs — which prevents source-level debugging (IntelliJ can't map JAR classes back to source files)
- Manually pull
libraryDependencies from each dependent project
Expected behavior
dependsOn(RootProject(...)) should work the same way it does in normal SBT projects:
- IntelliJ import should succeed without crashes
- External project class files should be included in the plugin artifact automatically
- External project library dependencies should be resolved and included automatically
packageArtifactDynamic should enable source-level debugging across module boundaries, including external project sources
Steps to reproduce
- Clone https://github.com/collaboncode/minimal-ij-plugin-setup
cd main-ij-plugin && sbt compile — succeeds
- Open
main-ij-plugin in IntelliJ as an SBT project — crashes
Minimal example
minimal-ij-plugin-setup/
├── non-ij-sbt-module/ # Normal SBT project with Greeter.scala
└── main-ij-plugin/ # IntelliJ plugin with dependsOn(RootProject(...))
└── build.sbt # dependsOn(RootProject(file("../non-ij-sbt-module")))
// main-ij-plugin/build.sbt
lazy val myLibrary = RootProject(file("../non-ij-sbt-module"))
lazy val myPlugin = project.in(file("."))
.enablePlugins(SbtIdeaPlugin)
.dependsOn(myLibrary)
Error 1: NoSuchElementException
java.util.NoSuchElementException: key not found:
ProjectRef(file:.../non-ij-sbt-module/,non-ij-sbt-module)
at org.jetbrains.sbtidea.structure.sbtImpl.SbtProjectStructureExtractorBase.topoSortRefs
Error 2: RuntimeUndefined
sbt.internal.util.Init$RuntimeUndefined: References to undefined settings at runtime.
ScopedKey(Scope(Select(ProjectRef(file:.../non-ij-sbt-module/,non-ij-sbt-module)), Zero, Zero, Zero),
intellijExtraRuntimePluginsInTests)
Versions
- sbt: 1.11.7
- sbt-idea-plugin: 5.1.0
- Scala: 3.7.4
- IntelliJ build: 253.31033.53 (IdeaCommunity)
sbt-idea-plugin:
dependsOn(RootProject(...))crashes on IntelliJ import and excludes external projects from packagingProblem
When an IntelliJ plugin project uses
dependsOn(RootProject(...))to depend on a normal SBT project, two errors occur during IntelliJ import:NoSuchElementExceptionintopoSortRefs—projectMap(root)crashes when the root is an externalProjectRefnot in the mapRuntimeUndefinedforintellijExtraRuntimePluginsInTests— settings aggregation viaScopeFilter(inDependencies(ThisProject))reaches external projects that don't have sbt-idea-plugin enabledAdditionally, even after working around the crashes, external projects are excluded from the packaging graph — their class files and library dependencies are never included in the plugin artifact. This forces users to:
packageFileMappingswith explicit JARs — which prevents source-level debugging (IntelliJ can't map JAR classes back to source files)libraryDependenciesfrom each dependent projectExpected behavior
dependsOn(RootProject(...))should work the same way it does in normal SBT projects:packageArtifactDynamicshould enable source-level debugging across module boundaries, including external project sourcesSteps to reproduce
cd main-ij-plugin && sbt compile— succeedsmain-ij-pluginin IntelliJ as an SBT project — crashesMinimal example
Error 1:
NoSuchElementExceptionError 2:
RuntimeUndefinedVersions