Skip to content

Conversation

@MkDev11
Copy link
Contributor

@MkDev11 MkDev11 commented Jan 14, 2026

Fix scalaHome support for Scala 2.13/3 build directories

Fixes sbt/sbt#7477

The Problem

When using scalaHome with a Scala checkout (e.g., for testing local Scala changes), sbt fails with:

[error] (scalaInstance) sbt.internal.inc.InvalidScalaInstance: Scala instance doesn't exist or is invalid: (library jar /path/to/scala/lib/scala-library.jar)

This happens because zinc expects Scala jars in $scalaHome/lib/, but:

  • Scala 2.13 builds from source put jars in $scalaHome/build/pack/lib/ after running dist/mkPack
  • Scala 3 builds may put jars in $scalaHome/dist/target/pack/lib/

The Fix

Update ScalaInstance.scalaLib() to check multiple candidate directories:

  1. lib/ (traditional/installed Scala)
  2. build/pack/lib/ (Scala 2.13 after dist/mkPack)
  3. dist/target/pack/lib/ (Scala 3 builds)

Also update libraryJar() to support both:

  • Scala 2: scala-library.jar
  • Scala 3: scala3-library_3-*.jar

Testing

With this fix, the following now works without the symlink workaround:

scalaVersion := "2.13.12"
scalaHome := Some(file("/path/to/scala213-checkout"))

After running dist/mkPack in the Scala checkout, sbt compile and sbt run work correctly.

Fixes sbt/sbt#7477

When using scalaHome with a Scala checkout, the lib directory may be in
different locations depending on the build system:
- lib/ (traditional/installed Scala)
- build/pack/lib/ (Scala 2.13 after dist/mkPack)
- dist/target/pack/lib/ (Scala 3 builds)

This change updates scalaLib() to check these candidate directories and
use the first one that contains a Scala library jar.

Also updates libraryJar() to support both Scala 2 (scala-library.jar)
and Scala 3 (scala3-library_3-*.jar) library jar naming.
@MkDev11 MkDev11 force-pushed the fix/scalaHome-alternative-lib-dirs-7477 branch from b09f20d to cf370e4 Compare January 14, 2026 13:23
@MkDev11
Copy link
Contributor Author

MkDev11 commented Jan 14, 2026

@eed3si9n please review the push and let me know the result

Copy link
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eed3si9n eed3si9n changed the title fix: Support alternative Scala lib directories for scalaHome [2.x] fix: Support alternative Scala lib directories for scalaHome Jan 14, 2026
@eed3si9n eed3si9n merged commit 603764e into sbt:develop Jan 14, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scalaHome support is bitrotted, requires workaround to use with Scala 2.13

2 participants