[2.x]fix: Non-fork test classloader respects autoScalaLibrary#8776
Merged
eed3si9n merged 2 commits intosbt:developfrom Feb 21, 2026
Merged
Conversation
When Test / autoScalaLibrary := false, build the non-fork test classloader without the ScalaInstance layer: use Flat strategy and project classpath only (rawCP), so tests do not see sbt's scala-library and avoid NoSuchMethodError / version mismatch (e.g. scala/scala build). - ClassLoaders.testTask: read autoScalaLibrary; when false use Flat and rawCP-only fullCP, and do not add si.libraryJars to exclude. - Add scripted test tests/autoScalaLibrary-test-loader that runs test with Test / autoScalaLibrary := false.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With
Test / autoScalaLibrary := false, the non-fork test classloader still included the ScalaInstance-based scala-library layer. Tests could load the wrong scala-library (e.g. sbt's) and hitNoSuchMethodErroror version mismatch (e.g. scala/scala had to usefork in Test := trueas a workaround).Solution
In
ClassLoaders.testTask:autoScalaLibrary.valueis false, useClassLoaderLayeringStrategy.Flatso the test classloader is built without the ScalaInstance layer.rawCP) forfullCPin that case (do not prependsi.libraryJars).si.libraryJarsto the exclude set whenautoScalaLibraryis false.No change to forked tests or to the
runtask.Verification
Test / autoScalaLibrary := falseand a test framework that pulls in Scala (e.g. ScalaCheck), runtestwithout forking; previously the framework could load scala-library from the ScalaInstance layer and fail (e.g.NoSuchMethodError: scala.collection.immutable.Set$.apply).testsuccessfully with this fix (test classloader uses only project classpath)../sbt "scripted tests/autoScalaLibrary-test-loader"— runs tests withTest / autoScalaLibrary := false../sbt "scripted classloader-cache/scalatest"— passes.Tests / lint
./sbt compile— success./sbt "scripted tests/autoScalaLibrary-test-loader"— success./sbt "scripted classloader-cache/scalatest"— successCloses #4009