Skip to content

Commit

Permalink
add support for sbt-assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
somdoron committed Jun 17, 2020
1 parent 1db3efa commit dd15e6f
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
16 changes: 16 additions & 0 deletions src/main/scala/AssemblyHelpers.scala
Original file line number Diff line number Diff line change
@@ -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)
)

}
6 changes: 6 additions & 0 deletions src/main/scala/ReproducibleBuildsPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ object ReproducibleBuildsPlugin extends AutoPlugin {
val gpgPluginOnClasspath =
Try(getClass.getClassLoader.loadClass("io.crashbox.gpg.SbtGpg")).isSuccess

val assemblyPluginOnClasspath =
Try(getClass.getClassLoader.loadClass("sbtassembly.AssemblyPlugin")).isSuccess

override def requires: Plugins = JvmPlugin

val ReproducibleBuilds = config("reproducible-builds")
Expand Down Expand Up @@ -211,6 +214,9 @@ object ReproducibleBuildsPlugin extends AutoPlugin {
) ++ (
if (universalPluginOnClasspath) SbtNativePackagerHelpers.settings
else Seq.empty
) ++ (
if (assemblyPluginOnClasspath) AssemblyHelpers.settings
else Seq.empty
) ++ inConfig(ReproducibleBuilds)(Seq(
packagedArtifacts := {
val compiledArtifacts = (packagedArtifacts in Compile).value
Expand Down
4 changes: 4 additions & 0 deletions src/sbt-test/sbt-reproducible-builds/assembly/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scalaVersion := "2.12.7"

enablePlugins(ReproducibleBuildsPlugin)
enablePlugins(AssemblyPlugin)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.3.12
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.bzzt

object Main extends App {
println("Hello, Reproducible World")
}
3 changes: 3 additions & 0 deletions src/sbt-test/sbt-reproducible-builds/assembly/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> assembly
$ 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

0 comments on commit dd15e6f

Please sign in to comment.