From 805b9cbc89fcd2d5b3f615445c1ba0c479ce69e2 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Fri, 2 Feb 2024 16:20:41 +0100 Subject: [PATCH] Cache output of assembly Previously, the build would rebuild over and over the uber jar with the shaded protobuf3 distribution. With this patch, this is no longer the case, as the output is cached locally. --- build.sbt | 15 +++++++++++++-- project/Protobuf.scala | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index e2d172f220..230490a690 100644 --- a/build.sbt +++ b/build.sbt @@ -368,8 +368,19 @@ lazy val protobufV3 = pekkoModule("protobuf-v3") Compile / packageBin / packagedArtifact := Scoped.mkTuple2( (Compile / packageBin / artifact).value, ReproducibleBuildsPlugin.postProcessJar(OsgiKeys.bundle.value)), - Compile / packageBin := ReproducibleBuildsPlugin - .postProcessJar((Compile / assembly).value), // package by running assembly + Compile / packageBin := Def.taskDyn { + val store = streams.value.cacheStoreFactory.make("shaded-output") + val uberJarLocation = (assembly / assemblyOutputPath).value + val tracker = Tracked.outputChanged(store) { (changed: Boolean, file: File) => + if (changed) { + Def.task { + val uberJar = (Compile / assembly).value + ReproducibleBuildsPlugin.postProcessJar(uberJar) + } + } else Def.task { file } + } + tracker(() => uberJarLocation) + }.value, // Prevent cyclic task dependencies, see https://github.com/sbt/sbt-assembly/issues/365 by // redefining the fullClasspath with just what we need to avoid the cyclic task dependency assembly / fullClasspath := (Runtime / managedClasspath).value ++ (Compile / products).value.map(Attributed.blank), diff --git a/project/Protobuf.scala b/project/Protobuf.scala index ed346aa94f..dccaf896fa 100644 --- a/project/Protobuf.scala +++ b/project/Protobuf.scala @@ -38,7 +38,7 @@ object Protobuf { outputPaths := Seq((Compile / sourceDirectory).value, (Test / sourceDirectory).value).map(_ / "java"), importPath := None, // this keeps intellij happy for files that use the shaded protobuf - Compile / unmanagedJars += (LocalProject("protobuf-v3") / assembly).value, + Compile / unmanagedJars += (LocalProject("protobuf-v3") / Compile / packageBin).value, protoc := "protoc", protocVersion := "3.11.4", generate := {