Skip to content

Commit

Permalink
Merge pull request #432 from eed3si9n/wip/drop
Browse files Browse the repository at this point in the history
Drop deprecated keys
  • Loading branch information
eed3si9n authored Jun 6, 2021
2 parents 28e6ddc + 671a81d commit 226282d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 52 deletions.
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,13 @@ ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "com.example"
ThisBuild / scalaVersion := "2.13.6"

lazy val commonSettings = Seq(
Compile / assembly / test := {}
)

lazy val app = (project in file("app"))
.settings(commonSettings)
.settings(
Compile / assembly / mainClass := Some("com.example.Main"),
// more settings here ...
)

lazy val utils = (project in file("utils"))
.settings(commonSettings)
.settings(
Compile / assembly / assemblyJarName := "utils.jar",
// more settings here ...
Expand All @@ -78,7 +72,7 @@ single JAR file: `target/scala_X.X.X/projectname-assembly-X.X.X.jar`.
If you specify a `mainClass in assembly` in build.sbt (or just let it autodetect
one) then you'll end up with a fully executable JAR, ready to rock.

Here is the list of the keys you can rewire for `assembly` task.
Here is the list of the keys you can rewire for `assembly` task.

assemblyJarName test mainClass
assemblyOutputPath assemblyMergeStrategy assemblyOption
Expand All @@ -87,29 +81,45 @@ Here is the list of the keys you can rewire for `assembly` task.
For example the name of the jar can be set as follows in build.sbt:

```scala
Compile / assembly / assemblyJarName := "something.jar"
lazy val app = (project in file("app"))
.settings(
Compile / assembly / assemblyJarName := "something.jar",
// more settings here ...
)
```

To skip the test during assembly,
To set an explicit main class,

```scala
Compile / assembly / test := {}
lazy val app = (project in file("app"))
.settings(
Compile / assembly / mainClass := Some("com.example.Main"),
// more settings here ...
)
```

To set an explicit main class,
To run the test during assembly,

```scala
Compile / assembly / mainClass := Some("com.example.Main")
lazy val app = (project in file("app"))
.settings(
Compile / assembly / test := (Test / test).value,
// more settings here ...
)
```

Excluding an explicit main class from your assembly requires something a little bit different though

```
Compile / assembly / packageOptions ~= { pos =>
pos.filterNot { po =>
po.isInstanceOf[Package.MainClass]
}
}
lazy val app = (project in file("app"))
.settings(
Compile / assembly / packageOptions ~= { pos =>
pos.filterNot { po =>
po.isInstanceOf[Package.MainClass]
}
},
// more settings here ...
)
```

### Merge Strategy
Expand Down Expand Up @@ -233,7 +243,7 @@ To see the verbose output for shading:
#### Scala libraries

Scala classes contain an annotation which, among other things, contain all symbols referenced in that class. As of sbt-assembly XXX the rename rules
will be applied to these annotations as well which makes it possible to compile or reflect against a shaded library.
will be applied to these annotations as well which makes it possible to compile or reflect against a shaded library.

This is currently limited to renaming packages. Renaming class names will not work and cause compiler errors when compiling against the shaded library.

Expand Down
21 changes: 0 additions & 21 deletions src/main/scala/sbtassembly/AssemblyKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,12 @@ trait AssemblyKeys {
lazy val assembledMappings = taskKey[Seq[MappingSet]]("Keeps track of jar origins for each source.")

lazy val assemblyPackageScala = taskKey[File]("Produces the scala artifact.")
@deprecated("Use assemblyPackageScala", "0.12.0")
lazy val packageScala = assemblyPackageScala

lazy val assemblyPackageDependency = taskKey[File]("Produces the dependency artifact.")
@deprecated("Use assemblyPackageDependency", "0.12.0")
lazy val packageDependency = assemblyPackageDependency

lazy val assemblyJarName = taskKey[String]("name of the fat jar")
@deprecated("Use assemblyJarName", "0.12.0")
lazy val jarName = assemblyJarName

lazy val assemblyDefaultJarName = taskKey[String]("default name of the fat jar")
@deprecated("Use assemblyDefaultJarName", "0.12.0")
lazy val defaultJarName = assemblyDefaultJarName

lazy val assemblyOutputPath = taskKey[File]("output path of the fat jar")
@deprecated("Use assemblyOutputPath", "0.12.0")
lazy val outputPath = assemblyOutputPath

lazy val assemblyExcludedJars = taskKey[Classpath]("list of excluded jars")
@deprecated("Use assemblyExcludedJars", "0.12.0")
lazy val excludedJars = assemblyExcludedJars

lazy val assemblyMergeStrategy = settingKey[String => MergeStrategy]("mapping from archive member path to merge strategy")
@deprecated("Use assemblyMergeStrategy", "0.12.0")
lazy val mergeStrategy = assemblyMergeStrategy

lazy val assemblyShadeRules = settingKey[Seq[jarjarabrams.ShadeRule]]("shading rules backed by jarjar")
}
object AssemblyKeys extends AssemblyKeys
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/sbtassembly/AssemblyPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object AssemblyPlugin extends sbt.AutoPlugin {
assembledMappings in assemblyPackageDependency := Assembly.assembledMappingsTask(assemblyPackageDependency).value,

// test
test in assembly := (test in Test).value,
test in assembly := { () },
test in assemblyPackageScala := (test in assembly).value,
test in assemblyPackageDependency := (test in assembly).value,

Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/merging/mergefail/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
lazy val testmerge = (project in file(".")).
settings(
version := "0.1",
jarName in assembly := "foo.jar",
assemblyJarName in assembly := "foo.jar",
mergeStrategy in assembly := {
val old = (mergeStrategy in assembly).value

Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/merging/mergefail2/build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lazy val testmerge = (project in file(".")).
settings(
version := "0.1",
jarName in assembly := "foo.jar"
assemblyJarName in assembly := "foo.jar"
)
20 changes: 10 additions & 10 deletions src/sbt-test/merging/merging/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ lazy val testmerge = (project in file(".")).
version := "0.1",
assemblyJarName in assembly := "foo.jar",
scalaVersion := "2.11.12",
mergeStrategy in assembly := {
case "a" MergeStrategy.concat
case "b" MergeStrategy.first
case "c" MergeStrategy.last
case "d" MergeStrategy.filterDistinctLines
case "e" MergeStrategy.deduplicate
case "f" MergeStrategy.discard
case PathList("x", "y") MergeStrategy.discard
case x
val oldStrategy = (mergeStrategy in assembly).value
assemblyMergeStrategy in assembly := {
case "a" => MergeStrategy.concat
case "b" => MergeStrategy.first
case "c" => MergeStrategy.last
case "d" => MergeStrategy.filterDistinctLines
case "e" => MergeStrategy.deduplicate
case "f" => MergeStrategy.discard
case PathList("x", "y") => MergeStrategy.discard
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
},
TaskKey[Unit]("check") := {
Expand Down

0 comments on commit 226282d

Please sign in to comment.