From 1a8b9de625e8ef217cb2b86abef60e5fad489faa Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Sun, 26 May 2019 16:45:17 -0700 Subject: [PATCH] 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. --- testing/src/main/scala/sbt/TestFramework.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testing/src/main/scala/sbt/TestFramework.scala b/testing/src/main/scala/sbt/TestFramework.scala index dcaa6c717..71fe4790d 100644 --- a/testing/src/main/scala/sbt/TestFramework.scala +++ b/testing/src/main/scala/sbt/TestFramework.scala @@ -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()) }