Skip to content

Commit

Permalink
Cache output of assembly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Duhemm committed Feb 14, 2024
1 parent 231b9a9 commit f4e48f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion project/Protobuf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 := {
Expand Down

0 comments on commit f4e48f9

Please sign in to comment.