Re-posting this here for awareness. Lots of Scala Community-Build projects are not running or even compiling their tests. They are silently failing with:
[error] Error loading test framework (java.lang.NoClassDefFoundError: sbt/testing/Framework). This usually means that you are using a layered class loader that cannot reach the sbt.testing.Framework class. The most likely cause is that your project has a runtime dependency on your test framework, e.g. scalatest. To fix this, you can try to set
or something similar. I think (am not 100% sure) that the following projects are affected:
in community-build-a
scalatest
scala-stm
scalatestplus-testng
izumi-reflect
Lucre
in community-build-c
protoquill (I got this one…)
akka
jackson-module-scala
libretto
xml-interpolator
scalatestplus-scalacheck
scala-parallel-collections
sconfig
onnx-scala
We are discussing this issue here:
opened 06:11PM - 31 Jan 22 UTC
itype:bug
area:infrastructure
prio:blocker
It looks like lots of Builds not running or even compiling their tests. When the… y get to testing this happens:
```
2022-01-30T08:16:22.4896099Z [error] Error loading test framework (java.lang.NoClassDefFoundError: sbt/testing/Framework). This usually means that you are using a layered class loader that cannot reach the sbt.testing.Framework class. The most likely cause is that your project has a runtime dependency on your test framework, e.g. scalatest. To fix this, you can try to set
2022-01-30T08:16:22.4899342Z [error] Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.ScalaLibrary
2022-01-30T08:16:22.4900029Z [error] or
2022-01-30T08:16:22.4900718Z [error] Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat
2022-01-30T08:16:22.5477827Z [success] Total time: 23 s, completed Jan 30, 2022 9:16:22 AM
```
As similar issues happens for some builds trying to use ZTestFramework:
```
2022-01-30T08:21:26.8954542Z [error] Error loading test framework (scala.MatchError: zio.test.sbt.ZTestFramework@31fd0360 (of class zio.test.sbt.ZTestFramework)). This usually means that you are using a layered class loader that cannot reach the sbt.testing.Framework class. The most likely cause is that your project has a runtime dependency on your test framework, e.g. scalatest. To fix this, you can try to set
```
When this error occurs in a project, none of the tests will be run or even compiled. It is effectively a total disabling of testing code for the given project.
I first saw these in the my quill PR builds:
![Screenshot from 2022-01-31 11-48-26](https://user-images.githubusercontent.com/1369480/151836718-57140a9e-5b0d-462f-9925-cf68e5aa2fea.png)
Some quick grepping (attached) shows me this is happening for the following projects:
#### in community-build-a
- scalatest
- scala-stm
- scalatestplus-testng
- izumi-reflect
- Lucre
#### in community-build-c
- protoquill (I got this one...)
- akka
- jackson-module-scala
- libretto
- xml-interpolator
- scalatestplus-scalacheck
- scala-parallel-collections
- sconfig
- onnx-scala
I solved this problem by adding something slightly different to my settings:
```
Compile / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat
```
When I added this, the error went away.
This could all be totally wrong and my grepping could be incorrect too but I've tried this with the quill build. I tried running the community build with and actual compile error in my scalatests and without the classLoaderLayeringStrategy parameter. The build passes as though nothing is wrong.
I think that project owners should maybe have a look at their builds and see if this is happening for them.
[grepping_results.txt](https://github.com/lampepfl/dotty/files/7972659/grepping_results.txt)
5 Likes