diff --git a/contrib/playlib/src/mill/playlib/RouteCompilerWorker.scala b/contrib/playlib/src/mill/playlib/RouteCompilerWorker.scala index 58ec70f3cdb..d0c695bff66 100644 --- a/contrib/playlib/src/mill/playlib/RouteCompilerWorker.scala +++ b/contrib/playlib/src/mill/playlib/RouteCompilerWorker.scala @@ -5,7 +5,7 @@ import mill.playlib.api.{RouteCompilerType, RouteCompilerWorkerApi} import mill.scalalib.api.CompilationResult import mill.{Agg, T} -private[playlib] class RouteCompilerWorker { +private[playlib] class RouteCompilerWorker extends AutoCloseable { private var routeCompilerInstanceCache = Option.empty[(Long, mill.playlib.api.RouteCompilerWorkerApi)] @@ -63,4 +63,8 @@ private[playlib] class RouteCompilerWorker { case err => Result.Failure(err) } } + + override def close(): Unit = { + routeCompilerInstanceCache = None + } } diff --git a/contrib/scalapblib/src/ScalaPBWorker.scala b/contrib/scalapblib/src/ScalaPBWorker.scala index 223f69bb4ce..3d0525705be 100644 --- a/contrib/scalapblib/src/ScalaPBWorker.scala +++ b/contrib/scalapblib/src/ScalaPBWorker.scala @@ -9,7 +9,7 @@ import mill.api.PathRef import mill.T import mill.define.{Discover, ExternalModule, Worker} -class ScalaPBWorker { +class ScalaPBWorker extends AutoCloseable { private var scalaPBInstanceCache = Option.empty[(Long, ScalaPBWorkerApi)] @@ -100,6 +100,10 @@ class ScalaPBWorker { mill.api.Result.Success(PathRef(dest)) } + + override def close(): Unit = { + scalaPBInstanceCache = None + } } trait ScalaPBWorkerApi { diff --git a/contrib/scoverage/src/ScoverageReportWorker.scala b/contrib/scoverage/src/ScoverageReportWorker.scala index 49b9aca2f18..a5236a3cfd8 100644 --- a/contrib/scoverage/src/ScoverageReportWorker.scala +++ b/contrib/scoverage/src/ScoverageReportWorker.scala @@ -5,7 +5,7 @@ import mill.api.{ClassLoader, Ctx} import mill.contrib.scoverage.api.ScoverageReportWorkerApi import mill.define.{Discover, ExternalModule, Worker} -class ScoverageReportWorker { +class ScoverageReportWorker extends AutoCloseable { private[this] var scoverageClCache = Option.empty[(Long, ClassLoader)] def bridge(classpath: Agg[os.Path])(implicit ctx: Ctx): ScoverageReportWorkerApi = { @@ -31,6 +31,10 @@ class ScoverageReportWorker { .newInstance() .asInstanceOf[api.ScoverageReportWorkerApi] } + + override def close(): Unit = { + scoverageClCache = None + } } object ScoverageReportWorker extends ExternalModule { diff --git a/scalajslib/src/ScalaJSWorkerApi.scala b/scalajslib/src/ScalaJSWorkerApi.scala index 3b1a4c51724..fd454f59c17 100644 --- a/scalajslib/src/ScalaJSWorkerApi.scala +++ b/scalajslib/src/ScalaJSWorkerApi.scala @@ -6,7 +6,7 @@ import mill.api.{Ctx, Result} import mill.define.Discover import mill.scalajslib.api._ import mill.{Agg, T} -class ScalaJSWorker { +class ScalaJSWorker extends AutoCloseable { private var scalaInstanceCache = Option.empty[(Long, ScalaJSWorkerApi)] private def bridge(toolsClasspath: Agg[os.Path])(implicit ctx: Ctx.Home) = { @@ -68,6 +68,9 @@ class ScalaJSWorker { bridge(toolsClasspath).getFramework(config, frameworkName, linkedFile, moduleKind) } + override def close(): Unit = { + scalaInstanceCache = None + } } object ScalaJSWorkerApi extends mill.define.ExternalModule { diff --git a/scalalib/src/scalafmt/ScalafmtWorker.scala b/scalalib/src/scalafmt/ScalafmtWorker.scala index 5fa9822c309..c1d61d8f839 100644 --- a/scalalib/src/scalafmt/ScalafmtWorker.scala +++ b/scalalib/src/scalafmt/ScalafmtWorker.scala @@ -14,7 +14,7 @@ object ScalafmtWorkerModule extends ExternalModule { lazy val millDiscover = Discover[this.type] } -private[scalafmt] class ScalafmtWorker { +private[scalafmt] class ScalafmtWorker extends AutoCloseable { private val reformatted: mutable.Map[os.Path, Int] = mutable.Map.empty private var configSig: Int = 0 @@ -94,4 +94,8 @@ private[scalafmt] class ScalafmtWorker { } } + override def close(): Unit = { + reformatted.clear() + configSig = 0 + } } diff --git a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala index e0b331886e5..4aff9d9a04a 100644 --- a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala +++ b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala @@ -27,7 +27,7 @@ class ZincWorkerImpl( compilerJarNameGrep: (Agg[os.Path], String) => os.Path, compilerCache: KeyedLockedCache[Compilers], compileToJar: Boolean -) extends ZincWorkerApi { +) extends ZincWorkerApi with AutoCloseable { private val ic = new sbt.internal.inc.IncrementalCompilerImpl() lazy val javaOnlyCompilers = { // Keep the classpath as written by the user @@ -558,4 +558,8 @@ class ZincWorkerImpl( reporter.foreach(_.finish()) } } + + override def close(): Unit = { + classloaderCache.clear() + } } diff --git a/scalanativelib/src/ScalaNativeWorkerApi.scala b/scalanativelib/src/ScalaNativeWorkerApi.scala index 71a4fefd096..6cdb4813627 100644 --- a/scalanativelib/src/ScalaNativeWorkerApi.scala +++ b/scalanativelib/src/ScalaNativeWorkerApi.scala @@ -7,7 +7,7 @@ import mill.define.{Discover, Worker} import mill.{Agg, T} import mill.scalanativelib.api._ -class ScalaNativeWorker { +class ScalaNativeWorker extends AutoCloseable { private var scalaInstanceCache = Option.empty[(Long, ScalaNativeWorkerApi)] def impl(toolsClasspath: Agg[os.Path])(implicit ctx: mill.api.Ctx.Home): ScalaNativeWorkerApi = { @@ -37,6 +37,11 @@ class ScalaNativeWorker { } } } + + override def close(): Unit = { + // drop instance + scalaInstanceCache = None + } } object ScalaNativeWorkerApi extends mill.define.ExternalModule {