mirror of https://github.com/sbt/sbt.git
commit
499b6ab8be
|
|
@ -96,5 +96,5 @@ object ClassLoaderLayeringStrategy {
|
||||||
/**
|
/**
|
||||||
* Add a layer on top of the ScalaLibrary layer for all of the jar dependencies.
|
* Add a layer on top of the ScalaLibrary layer for all of the jar dependencies.
|
||||||
*/
|
*/
|
||||||
object AllLibraryJars extends AllLibraryJars
|
case object AllLibraryJars extends AllLibraryJars
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ private[sbt] object ClassLoaders {
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Create a layered classloader. There are up to four layers:
|
* Create a layered classloader. There are up to four layers:
|
||||||
* 1) the scala instance class loader
|
* 1) the scala instance class loader (may actually be two layers if scala-reflect is used)
|
||||||
* 2) the resource layer
|
* 2) the resource layer
|
||||||
* 3) the dependency jars
|
* 3) the dependency jars
|
||||||
* 4) the rest of the classpath
|
* 4) the rest of the classpath
|
||||||
|
|
@ -132,15 +132,21 @@ private[sbt] object ClassLoaders {
|
||||||
case _: AllLibraryJars => true
|
case _: AllLibraryJars => true
|
||||||
case _ => false
|
case _ => false
|
||||||
}
|
}
|
||||||
val allDependenciesSet = allDependencies.toSet
|
|
||||||
val scalaLibraryLayer = layer(si.libraryJars, interfaceLoader, cache, resources, tmp)
|
val scalaLibraryLayer = layer(si.libraryJars, interfaceLoader, cache, resources, tmp)
|
||||||
val cpFiles = fullCP.map(_._1)
|
val cpFiles = fullCP.map(_._1)
|
||||||
|
|
||||||
|
val scalaReflectJar = allDependencies.find(_.getName == "scala-reflect.jar")
|
||||||
|
val scalaReflectLayer = scalaReflectJar
|
||||||
|
.map { file =>
|
||||||
|
layer(file :: Nil, scalaLibraryLayer, cache, resources, tmp)
|
||||||
|
}
|
||||||
|
.getOrElse(scalaLibraryLayer)
|
||||||
|
|
||||||
// layer 2 (resources)
|
// layer 2 (resources)
|
||||||
val resourceLayer =
|
val resourceLayer =
|
||||||
if (layerDependencies)
|
if (layerDependencies)
|
||||||
getResourceLayer(cpFiles, resourceCP, scalaLibraryLayer, cache, resources)
|
getResourceLayer(cpFiles, resourceCP, scalaReflectLayer, cache, resources)
|
||||||
else scalaLibraryLayer
|
else scalaReflectLayer
|
||||||
|
|
||||||
// layer 3 (optional if in the test config and the runtime layer is not shared)
|
// layer 3 (optional if in the test config and the runtime layer is not shared)
|
||||||
val dependencyLayer =
|
val dependencyLayer =
|
||||||
|
|
@ -148,7 +154,10 @@ private[sbt] object ClassLoaders {
|
||||||
else resourceLayer
|
else resourceLayer
|
||||||
|
|
||||||
// layer 4
|
// layer 4
|
||||||
val dynamicClasspath = cpFiles.filterNot(allDependenciesSet ++ si.libraryJars)
|
val filteredSet =
|
||||||
|
if (layerDependencies) allDependencies.toSet ++ si.libraryJars ++ scalaReflectJar
|
||||||
|
else Set(si.libraryJars ++ scalaReflectJar: _*)
|
||||||
|
val dynamicClasspath = cpFiles.filterNot(filteredSet)
|
||||||
new LayeredClassLoader(dynamicClasspath, dependencyLayer, resources, tmp)
|
new LayeredClassLoader(dynamicClasspath, dependencyLayer, resources, tmp)
|
||||||
}
|
}
|
||||||
ClasspathUtilities.filterByClasspath(cpFiles, raw)
|
ClasspathUtilities.filterByClasspath(cpFiles, raw)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
> set Compile / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.AllLibraryJars
|
||||||
|
|
||||||
-> run
|
-> run
|
||||||
|
|
||||||
> set Compile / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat
|
> set Compile / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
> set Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.AllLibraryJars
|
||||||
|
|
||||||
> test
|
> test
|
||||||
|
|
||||||
> set Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat
|
> set Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat
|
||||||
|
|
@ -8,8 +10,14 @@
|
||||||
|
|
||||||
> test
|
> test
|
||||||
|
|
||||||
> set Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.AllLibraryJars
|
|
||||||
|
|
||||||
$ copy-file changes/bad.scala src/test/scala/sbt/ScalatestTest.scala
|
$ copy-file changes/bad.scala src/test/scala/sbt/ScalatestTest.scala
|
||||||
|
|
||||||
-> test
|
-> test
|
||||||
|
|
||||||
|
> set Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat
|
||||||
|
|
||||||
|
-> test
|
||||||
|
|
||||||
|
> set Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.AllLibraryJars
|
||||||
|
|
||||||
|
-> test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue