Open stevedlawrence opened 1 year ago
could you try Test / fork := true
please?
Forking tests fixes the issue, but we're hoping there's another solution. We take a big performance hit when we have to fork tests.
If I remember correctly JLine is near the bottom of the layered classloader so I don't think there's good solution for now.
One potential fix might be persistent worker that I proposed in https://eed3si9n.com/sbt-2.0-ideas
If sbt packages its classes and dependencies in an assembly jar (one of the ideas proposed in https://eed3si9n.com/sbt-2.0-ideas), sbt also can shade possibly conflicting dependencies like JLine under its own package, e.g., sbt.org.jline.reader.impl.LineReaderImpl
instead of org.jline.reader.impl.LineReaderImpl
. A caveat with shading dependencies is that it can create new problems as well as solve existing problems for some people (https://softwareengineering.stackexchange.com/questions/297276/what-is-a-shaded-java-dependency).
steps
Create a project with these files to run a test using JLine 3.23.0 to read a line from a buffer:
build.sbt
src/main/scala/Main.scala
src/test/scala/Test.scala
And run
sbt test
. You should get a failed test with this exception:problem
The new version of JLine modified
org.jline.utils.AttributedString
to add new functions (e.g.fromAnsi
) and calls them from theLineReaderImpl.getLine
function.However, the way sbt sets up the classloader,
LineReaderImpl
is found in thejline-3.23.0.jar
from in the Ivy cache, butAttributedString
is found in thejline-terminal-3.19.0.jar
in~/.sbt/boot/...
found via theJLineLoader
. The olderAttributedString
is not compatible work with the newerLineReaderImpl
, which leads to this exception.I suspect JLine 3.22 works because the older version of AttributedString that sbt provides works with newer versions of Jline. This is no longer that case with JLine 3.23.
expectation
When running tests, jars needed by SBT (e.g. jline) should not be found on the classpath, instead preferring those that come from dependencies.