Catch NoClassDefFoundErrors in tests

If a test threw a NoClassDefFoundError, it was uncaught and the user got
an obscure error. After this change, they will be warned that the
classloader layering strategy may be at fault and will get instructions
on how to fix it.
This commit is contained in:
Ethan Atkins 2019-05-26 16:45:17 -07:00
parent df628d4f87
commit 1a8b9de625
1 changed files with 4 additions and 3 deletions

View File

@ -52,7 +52,7 @@ final class TestFramework(val implClassNames: String*) extends Serializable {
+ " 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\n"
+ "Test / classLoaderLayeringStrategy := new ClassLoaderLayeringStrategy.Test(false, true)\nor\n"
+ "Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.ScalaLibrary\nor\n"
+ "Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat"
)
None
@ -138,8 +138,9 @@ final class TestRunner(
val nestedTasks =
try testTask.execute(handler, loggers.map(_.log).toArray)
catch {
case NonFatal(e) => errorEvents(e)
case e: IllegalAccessError => errorEvents(e)
case e: NoClassDefFoundError => errorEvents(e)
case NonFatal(e) => errorEvents(e)
case e: IllegalAccessError => errorEvents(e)
} finally {
loggers.foreach(_.flush())
}