Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for sbt-assembly #152

Merged
merged 2 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
somdoron marked this conversation as resolved.
Show resolved Hide resolved
)

}
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