From 399dd920b0578609936b0d15562672d4dbfd57f3 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Tue, 2 Apr 2019 16:39:05 -0700 Subject: [PATCH] Set bgCopyClasspath false for shared layer config It isn't possible to share the runtime and test layers correctly with bgCopyClasspath is used because the runtime classpath uses the dependencies copied to the boot directory while the test classpath uses the classes in target and .ivy2. Since this is not the default and users have to opt in to ClassLoaderLayeringStrategy.ShareRuntimeDependenciesLayerWithTestDependencies, I think this is fine. --- .../main/scala/sbt/ClassLoaderLayeringStrategy.scala | 4 +++- main/src/main/scala/sbt/Defaults.scala | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/main/src/main/scala/sbt/ClassLoaderLayeringStrategy.scala b/main/src/main/scala/sbt/ClassLoaderLayeringStrategy.scala index 89eae4f05..7245c2e8b 100644 --- a/main/src/main/scala/sbt/ClassLoaderLayeringStrategy.scala +++ b/main/src/main/scala/sbt/ClassLoaderLayeringStrategy.scala @@ -112,7 +112,9 @@ object ClassLoaderLayeringStrategy { * Add the TestDependencies layer on top of the RuntimeDependencies layer on top of the * ScalaInstance layer. This differs from TestDependencies in that it will not reload the * runtime classpath. The drawback to using this is that if the test dependencies evict - * classes provided in the runtime layer, then tests can fail. + * classes provided in the runtime layer, then tests can fail. In order for sharing the runtime + * layer to work, it is necessary to set [[Keys.bgCopyClasspath]] to false. Otherwise the + * runtime and test classpaths are completely different. */ case object ShareRuntimeDependenciesLayerWithTestDependencies extends ScalaInstance diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 107ff54b3..b504dd5c0 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -1781,7 +1781,15 @@ object Defaults extends BuildCommon { // by the test task layers may be cached without evicting the runtime classloader layers. The // cache size should be a multiple of two to support snapshot layers. ClassLoaderCache(4) - ) + ), + bgCopyClasspath in bgRun := { + val old = (bgCopyClasspath in bgRun).value + old && (Test / classLoaderLayeringStrategy).value != ClassLoaderLayeringStrategy.ShareRuntimeDependenciesLayerWithTestDependencies + }, + bgCopyClasspath in bgRunMain := { + val old = (bgCopyClasspath in bgRunMain).value + old && (Test / classLoaderLayeringStrategy).value != ClassLoaderLayeringStrategy.ShareRuntimeDependenciesLayerWithTestDependencies + }, ) lazy val testSettings: Seq[Setting[_]] = configSettings ++ testTasks ++