diff --git a/build.sbt b/build.sbt index dc3af1a..6676c8c 100644 --- a/build.sbt +++ b/build.sbt @@ -24,6 +24,7 @@ libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.2" % "test" // Optional integration: addSbtPlugin("com.typesafe.sbt" %% "sbt-native-packager" % "1.7.3" % Provided) addSbtPlugin("io.crashbox" %% "sbt-gpg" % "0.2.1" % Provided) +addSbtPlugin("com.eed3si9n" %% "sbt-assembly" % "0.14.10" % Provided) // addSbtPlugin("com.jsuereth" % "sbt-pgp" % sbtPgpVersion % Provided) licenses += ("MIT", url("https://opensource.org/licenses/MIT")) diff --git a/src/main/scala/AssemblyHelpers.scala b/src/main/scala/AssemblyHelpers.scala new file mode 100644 index 0000000..e236ca8 --- /dev/null +++ b/src/main/scala/AssemblyHelpers.scala @@ -0,0 +1,16 @@ +package net.bzzt.reproduciblebuilds + +import sbtassembly.{Assembly, AssemblyPlugin} +import sbtassembly.AssemblyPlugin.autoImport.{Assembly => _, baseAssemblySettings => _, _} +import sbt._ +import sbt.Keys._ + +object AssemblyHelpers { + val plugin: Plugins.Basic = AssemblyPlugin + + val settings: Seq[Setting[_]] = + Seq( + assembly := ReproducibleBuildsPlugin.postProcessJar(assembly.value) + ) + +} diff --git a/src/main/scala/ReproducibleBuildsAssemblyPlugin.scala b/src/main/scala/ReproducibleBuildsAssemblyPlugin.scala new file mode 100644 index 0000000..4cfee11 --- /dev/null +++ b/src/main/scala/ReproducibleBuildsAssemblyPlugin.scala @@ -0,0 +1,21 @@ +package net.bzzt.reproduciblebuilds + +import scala.util.Try + +import sbt._ +import sbt.plugins.JvmPlugin + +object ReproducibleBuildsAssemblyPlugin extends AutoPlugin { + val assemblyPluginOnClasspath = + Try(getClass.getClassLoader.loadClass("sbtassembly.AssemblyPlugin")).isSuccess + + override def requires: Plugins = + if (assemblyPluginOnClasspath) AssemblyHelpers.plugin + else JvmPlugin + + override def trigger = allRequirements + + override def projectSettings = + if (assemblyPluginOnClasspath) AssemblyHelpers.settings + else Seq.empty +} diff --git a/src/main/scala/ReproducibleBuildsPlugin.scala b/src/main/scala/ReproducibleBuildsPlugin.scala index feb4b20..57b32b7 100644 --- a/src/main/scala/ReproducibleBuildsPlugin.scala +++ b/src/main/scala/ReproducibleBuildsPlugin.scala @@ -30,6 +30,7 @@ object ReproducibleBuildsPlugin extends AutoPlugin { val gpgPluginOnClasspath = Try(getClass.getClassLoader.loadClass("io.crashbox.gpg.SbtGpg")).isSuccess + override def requires: Plugins = JvmPlugin val ReproducibleBuilds = config("reproducible-builds") diff --git a/src/sbt-test/sbt-reproducible-builds/assembly/build.sbt b/src/sbt-test/sbt-reproducible-builds/assembly/build.sbt new file mode 100644 index 0000000..241913f --- /dev/null +++ b/src/sbt-test/sbt-reproducible-builds/assembly/build.sbt @@ -0,0 +1,3 @@ +scalaVersion := "2.12.7" + +enablePlugins(ReproducibleBuildsPlugin) diff --git a/src/sbt-test/sbt-reproducible-builds/assembly/expected/assembly-assembly-0.1.0-SNAPSHOT.jar b/src/sbt-test/sbt-reproducible-builds/assembly/expected/assembly-assembly-0.1.0-SNAPSHOT.jar new file mode 100644 index 0000000..0504e4e Binary files /dev/null and b/src/sbt-test/sbt-reproducible-builds/assembly/expected/assembly-assembly-0.1.0-SNAPSHOT.jar differ diff --git a/src/sbt-test/sbt-reproducible-builds/assembly/project/build.properties b/src/sbt-test/sbt-reproducible-builds/assembly/project/build.properties new file mode 100644 index 0000000..654fe70 --- /dev/null +++ b/src/sbt-test/sbt-reproducible-builds/assembly/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.3.12 diff --git a/src/sbt-test/sbt-reproducible-builds/assembly/project/plugins.sbt b/src/sbt-test/sbt-reproducible-builds/assembly/project/plugins.sbt new file mode 100644 index 0000000..cdc7782 --- /dev/null +++ b/src/sbt-test/sbt-reproducible-builds/assembly/project/plugins.sbt @@ -0,0 +1,7 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("net.bzzt" % "sbt-reproducible-builds" % sys.props("plugin.version")) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} + +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10") diff --git a/src/sbt-test/sbt-reproducible-builds/assembly/src/main/scala/Main.scala b/src/sbt-test/sbt-reproducible-builds/assembly/src/main/scala/Main.scala new file mode 100644 index 0000000..f06dc23 --- /dev/null +++ b/src/sbt-test/sbt-reproducible-builds/assembly/src/main/scala/Main.scala @@ -0,0 +1,5 @@ +package net.bzzt + +object Main extends App { + println("Hello, Reproducible World") +} diff --git a/src/sbt-test/sbt-reproducible-builds/assembly/test b/src/sbt-test/sbt-reproducible-builds/assembly/test new file mode 100644 index 0000000..b0433eb --- /dev/null +++ b/src/sbt-test/sbt-reproducible-builds/assembly/test @@ -0,0 +1,4 @@ +> assembly +$ exists target/scala-2.12/assembly-assembly-0.1.0-SNAPSHOT.jar +$ exists target/scala-2.12/stripped/assembly-assembly-0.1.0-SNAPSHOT.jar +$ must-mirror target/scala-2.12/stripped/assembly-assembly-0.1.0-SNAPSHOT.jar expected/assembly-assembly-0.1.0-SNAPSHOT.jar