mirror of https://github.com/sbt/sbt.git
Fork run directly with 'java' to avoid additional class loader from 'scala' command. Fixes #702.
This commit is contained in:
parent
382b55402b
commit
b560ef280e
|
|
@ -24,7 +24,8 @@ class ForkRun(config: ForkOptions) extends ScalaRun
|
|||
|
||||
val scalaOptions = classpathOption(classpath) ::: mainClass :: options.toList
|
||||
val configLogged = if(config.outputStrategy.isDefined) config else config.copy(outputStrategy = Some(LoggedOutput(log)))
|
||||
val process = Fork.scala.fork(configLogged, scalaOptions)
|
||||
// fork with Java because Scala introduces an extra class loader (#702)
|
||||
val process = Fork.java.fork(configLogged, scalaOptions)
|
||||
def cancel() = {
|
||||
log.warn("Run canceled.")
|
||||
process.destroy()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
object CheckLoader {
|
||||
def main(args: Array[String]) { apply() }
|
||||
def apply() {
|
||||
val loader = getClass.getClassLoader
|
||||
val appLoader = ClassLoader.getSystemClassLoader
|
||||
assert(loader eq appLoader, "Application classes not loaded in the system class loader")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
name := "forked-test"
|
||||
|
||||
organization := "org.example"
|
||||
|
||||
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.10.0" % "test"
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import org.scalacheck._
|
||||
|
||||
object TestForked extends Properties("Forked loader") {
|
||||
property("Loaded from application loader") = Prop.secure {
|
||||
CheckLoader()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# This test verifies that the forked code is loaded in the application class loader.
|
||||
-> run
|
||||
-> test
|
||||
> set fork := true
|
||||
> run
|
||||
> test
|
||||
Loading…
Reference in New Issue