mirror of https://github.com/sbt/sbt.git
Improve ClassLoader layering error message
When a class on the project classpath is loaded via reflection by one of the parents of the project classloader, sbt run can fail with a mysterious ClassNotFoundException. This is expected behavior but it wasn't previously explained to the user. Ref https://github.com/sbt/sbt/issues/5410.
This commit is contained in:
parent
996ee5f0d6
commit
2c473fc31d
|
|
@ -78,7 +78,22 @@ class Run(private[sbt] val newLoader: Seq[File] => ClassLoader, trapExit: Boolea
|
||||||
val main = getMainMethod(mainClass, loader)
|
val main = getMainMethod(mainClass, loader)
|
||||||
invokeMain(loader, main, options)
|
invokeMain(loader, main, options)
|
||||||
} catch {
|
} catch {
|
||||||
case e: java.lang.reflect.InvocationTargetException => throw e.getCause
|
case e: java.lang.reflect.InvocationTargetException =>
|
||||||
|
e.getCause match {
|
||||||
|
case ex: ClassNotFoundException =>
|
||||||
|
val className = ex.getMessage
|
||||||
|
try {
|
||||||
|
loader.loadClass(className)
|
||||||
|
val msg =
|
||||||
|
s"$className is on the project classpath but not visible to the ClassLoader " +
|
||||||
|
"that attempted to load it.\n" +
|
||||||
|
"See https://www.scala-sbt.org/1.x/docs/In-Process-Classloaders.html for " +
|
||||||
|
"further information."
|
||||||
|
log.error(msg)
|
||||||
|
} catch { case NonFatal(_) => }
|
||||||
|
throw ex
|
||||||
|
case ex => throw ex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
def directExecute(): Try[Unit] =
|
def directExecute(): Try[Unit] =
|
||||||
Try(execute()) recover {
|
Try(execute()) recover {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue