Skip to content

dependsOn(RootProject(...)) crashes on IntelliJ import when depending on a non-IntelliJ SBT project #146

Description

@teeckoo

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:

  1. NoSuchElementException in topoSortRefsprojectMap(root) crashes when the root is an external ProjectRef not in the map
  2. 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

  1. Clone https://github.com/collaboncode/minimal-ij-plugin-setup
  2. cd main-ij-plugin && sbt compilesucceeds
  3. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions