Skip to content

Commit

Permalink
add support for sbt-assembly (#152)
Browse files Browse the repository at this point in the history
* add support for sbt-assembly

* Move assembly override to separate autoplugin

Co-authored-by: Arnout Engelen <arnout@bzzt.net>
  • Loading branch information
somdoron and raboof authored Jun 19, 2020
1 parent 1db3efa commit 2217a04
Show file tree
Hide file tree
Showing 10 changed files with 59 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)
)

}
21 changes: 21 additions & 0 deletions src/main/scala/ReproducibleBuildsAssemblyPlugin.scala
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions src/main/scala/ReproducibleBuildsPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 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,3 @@
scalaVersion := "2.12.7"

enablePlugins(ReproducibleBuildsPlugin)
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")
}
4 changes: 4 additions & 0 deletions src/sbt-test/sbt-reproducible-builds/assembly/test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2217a04

Please sign in to comment.